Public Sub StartupExample()
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 bgrBuffer(bgrImage.BytesPerLine * bgrImage.Height) As Byte
For i As Integer = 0 To bgrImage.Height - 1
bgrImage.GetRow(i, bgrBuffer, (i * bgrImage.BytesPerLine), bgrImage.BytesPerLine)
Next
Dim converter As New RasterColorConverter()
Dim cmykBuffer As Byte() = New Byte(bgrImage.Height * bgrImage.Width * 4 - 1) {}
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]()
Dim cmykImage As New RasterImage(RasterMemoryFlags.Conventional, bgrImage.Width, bgrImage.Height, 24, RasterByteOrder.Bgr, RasterViewPerspective.TopLeft, _
Nothing, IntPtr.Zero, 0)
converter.Start(ConversionColorFormat.Cmyk, ConversionColorFormat.Bgr, Nothing)
converter.ConvertToImage(cmykBuffer, _
0, _
cmykImage, _
bgrImage.Width, _
bgrImage.Height, _
0, _
CInt(bgrImage.BytesPerLine - (bgrImage.Width * (bgrImage.BitsPerPixel / 8))))
converter.Stop()
Dim outputFileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "ResultImage.bmp"
codecs.Save(cmykImage, outputFileName, RasterImageFormat.Bmp, 24)
bgrImage.Dispose()
cmykImage.Dispose()
Catch ex As Exception
MessageBox.Show(ex.ToString())
End Try
RasterColorConverter.Shutdown()
RasterCodecs.Shutdown()
End Sub |