Public Function GetCmykBufferFromImage(ByVal bgrImage As RasterImage) As Byte()
RasterColorConverter.Startup()
Dim bgrBuffer(bgrImage.BytesPerLine * bgrImage.Height) As Byte
Dim i As Integer
For i = 0 To bgrImage.Height - 1
bgrImage.GetRow(i, bgrBuffer, (i * bgrImage.BytesPerLine), bgrImage.BytesPerLine)
Next i
Dim converter As New RasterColorConverter()
Dim cmykBuffer(bgrImage.Height * bgrImage.Width * 4) As Byte
Try
converter.Start(ConversionColorFormat.Bgr, ConversionColorFormat.Cmyk, Nothing)
converter.Convert(bgrBuffer, _
0, _
cmykBuffer, _
0, _
bgrImage.Width, _
bgrImage.Height, _
CInt(bgrImage.BytesPerLine - (bgrImage.Width * (bgrImage.BitsPerPixel / 8))), _
0)
converter.Stop()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
RasterColorConverter.Shutdown()
Return cmykBuffer
End Function
Public Function GetImageFromCmykBuffer(ByVal cmykBuffer As Byte(), ByVal width As Integer, ByVal height As Integer) As RasterImage
RasterColorConverter.Startup()
Dim Converter As New RasterColorConverter()
Dim cmykImage As RasterImage = Nothing
Try
cmykImage = New RasterImage(RasterMemoryFlags.Conventional, width, height, 24, RasterByteOrder.Bgr, RasterViewPerspective.TopLeft, Nothing, IntPtr.Zero, 0)
Converter.Start(ConversionColorFormat.Cmyk, ConversionColorFormat.Bgr, Nothing)
Converter.ConvertToImage(cmykBuffer, _
0, _
cmykImage, _
width, _
height, _
0, _
CInt(cmykImage.BytesPerLine - (cmykImage.Width * (cmykImage.BitsPerPixel / 8))))
Converter.Stop()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
RasterColorConverter.Shutdown()
Return cmykImage
End Function
Public Sub SetParametersExample()
RasterCodecs.Startup()
Dim codecs As New RasterCodecs
RasterColorConverter.Startup()
Dim inputFileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "Image1.cmp"
Dim bgrImage As RasterImage = codecs.Load(inputFileName, 24, CodecsLoadByteOrder.Bgr, 1, 1)
Dim width As Integer = bgrImage.Width
Dim height As Integer = bgrImage.Height
Dim cmykBuffer() As Byte = GetCmykBufferFromImage(bgrImage)
Dim rgbBuffer(CInt(cmykBuffer.Length - cmykBuffer.Length / 4)) As Byte
Dim converter As New RasterColorConverter
Dim convParams As ConversionParameters = New ConversionParameters
convParams.Method = ConversionMethodFlags.UseBuiltIn Or ConversionMethodFlags.UseIcc
convParams.ActiveMethod = ConversionMethodFlags.UseBuiltIn
convParams.WhitePoint = New ConversionWhitePoint
Dim whitePoint As ConversionWhitePoint
whitePoint.WhitePoint = ConversionWhitePointType.D50
convParams.WhitePoint = whitePoint
convParams.CmykParameters = New ConversionCmykParameters
Dim cmykParameters As ConversionCmykParameters
cmykParameters.GcrLevel = 150
convParams.CmykParameters = cmykParameters
Try
converter.Start(ConversionColorFormat.Cmyk, ConversionColorFormat.Rgb, convParams)
converter.Convert(cmykBuffer, _
0, _
rgbBuffer, _
0, _
width, _
height, _
0, _
CInt(bgrImage.BytesPerLine - (bgrImage.Width * (bgrImage.BitsPerPixel / 8))))
convParams.Method = ConversionMethodFlags.ChangeActiveMethod Or ConversionMethodFlags.ChangeCmyk
convParams.ActiveMethod = ConversionMethodFlags.UseIcc
cmykParameters.Mask = ConversionCmykMask.Gcr
cmykParameters.GcrLevel = 175
convParams.CmykParameters = cmykParameters
converter.SetParameters(convParams)
converter.Convert(cmykBuffer, _
0, _
rgbBuffer, _
0, _
width, _
height, _
0, _
CInt(bgrImage.BytesPerLine - (bgrImage.Width * (bgrImage.BitsPerPixel / 8))))
converter.Stop()
Catch ex As Exception
MessageBox.Show(ex.Message)
rgbBuffer = Nothing
End Try
Dim outputFileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "ResultImage.bmp"
Dim cmykImage As RasterImage = GetImageFromCmykBuffer(cmykBuffer, width, height)
codecs.Save(cmykImage, outputFileName, RasterImageFormat.Bmp, 24)
RasterColorConverter.Shutdown()
RasterCodecs.Shutdown()
End Sub |