Welcome Guest! To enable all features, please Login or Register.



Last Go to last post Unread Go to first unread post
#1 Posted : Wednesday, December 22, 2010 9:15:15 AM(UTC)

Groups: Registered
Posts: 5

Using Leadtools Ver 17 and your example in WhitePoint Property to convert an RGB File to CMYK. The output file is still an RGB file. I changed the example Visual Basic output file from .bmp to .tif as a .bmp file can only be an RGB file. I've attached the sample file and the result.
Here's the code I used:

Visual Basic (Declaration)

Public Property WhitePoint() As ConversionWhitePoint

End Get
Set(ByVal value As ConversionWhitePoint)

End Set
End Property

Visual Basic Code

Public Sub WhitePointExampleExample()
' Initialize the RasterCodecs class
Dim codecs As RasterCodecs = New RasterCodecs

' StartUp the ColorConversion.

' The input file name
' Dim inputFileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "Image1.cmp"

' load the input image as Rgb.
'Dim inputFileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "Image1.cmp"
Dim rgbImage As RasterImage = codecs.Load("d:\testrgb.jpg", 24, CodecsLoadByteOrder.Rgb, 1, 1)

' Image buffer array
Dim rgbBuffer(rgbImage.BytesPerLine * rgbImage.Height) As Byte

' get image buffer
For i As Integer = 0 To rgbImage.Height - 1
rgbImage.GetRow(i, rgbBuffer, (i * rgbImage.BytesPerLine), rgbImage.BytesPerLine)
' Initialize the Cmyk buffer array
Dim cmykBuffer(CInt(rgbImage.Height * rgbImage.Width * 4)) As Byte

' Initialize a new Converter object
Dim converter As New RasterColorConverterEngine

' Initialize a new ConversionParameters new class object.
Dim convParams As ConversionParameters = New ConversionParameters

' Initialize the WhitePoint property class.
Dim whitePoint As ConversionWhitePoint = ConversionWhitePoint.Empty

' Set the WhitePoint property.
whitePoint.WhitePoint = ConversionWhitePointType.D50

' Set the XWhite property.
whitePoint.XWhite = 0

' Set the YWhite property.
whitePoint.YWhite = 0
convParams.WhitePoint = whitePoint

' Set the Quantization property.
convParams.Quantization = 8

' Set the Method property.
convParams.Method = ConversionMethodFlags.UseBuiltIn

' Set the ActiveMethod property.
convParams.ActiveMethod = ConversionMethodFlags.UseBuiltIn

' Set GcrLevel property.
Dim cmykParameters As New ConversionCmykParameters()
cmykParameters.GcrLevel = 150
convParams.CmykParameters = cmykParameters

' Start the ColorConversion.
converter.Start(ConversionColorFormat.Rgb, ConversionColorFormat.Cmyk, convParams)

' Convert Rgb to CMYK.
converter.Convert(rgbBuffer, 0, cmykBuffer, 0, rgbImage.Width, rgbImage.Height, CInt(rgbImage.BytesPerLine - (rgbImage.Width * (rgbImage.BitsPerPixel / 8))), 0)

' Stop the ColorConversion.

' Initialize an image to hold the converted buffer.
Dim cmykImage As RasterImage = New RasterImage(RasterMemoryFlags.Conventional, rgbImage.Width, rgbImage.Height, 24, RasterByteOrder.Bgr, RasterViewPerspective.TopLeft, Nothing, IntPtr.Zero, 0)

' Start the color conversion
converter.Start(ConversionColorFormat.Cmyk, ConversionColorFormat.Bgr, convParams)

' convert the image buffer
converter.ConvertToImage(cmykBuffer, 0, cmykImage, rgbImage.Width, rgbImage.Height, 0, CInt(rgbImage.BytesPerLine - (rgbImage.Width * (rgbImage.BitsPerPixel / 8))))

' stop the conversion

' the output File Name.
' Dim outputFileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "ResultImage.bmp"

' Save the result image.
codecs.Save(cmykImage, "d:\testcmykoutput.tif", RasterImageFormat.Tif, 24)

' dispose the used images
Catch ex As Exception
End Try
' Shutdown the ColorConversion.
End Sub
File Attachment(s):
testcmykoutput.zip (499kb) downloaded 29 time(s).

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

#2 Posted : Thursday, December 23, 2010 1:20:58 AM(UTC)

Adnan Ismail  

Groups: Guests
Posts: 3,022

Was thanked: 2 time(s) in 2 post(s)

The ConvertToImage() method does not maintain the CMYK data. It will create a LEAD RGB bitmap from the CMYK buffers.

If the buffers contain the correct CMYK data you need, the best way to keep that data and save it to TIFF would be:
1. Create 4 bitmaps, one from each CMYK plane. Each bitmap will be 8-bit grayscale.
2. Create one RasterImage object that has 4 pages. The pages should be the C, M, Y and K grayscale images in that order.
3. Save the resulting 4-plane RasterImage to a CMYK tiff format such as TifCmyk or TifLzwCmyk using the  RasterCodecs.SaveCmykPlanes() method.

Please read the help topic "Handling CMYK Files as Separate Images" in our .NET help file.
#3 Posted : Thursday, December 23, 2010 7:15:43 AM(UTC)

Groups: Registered
Posts: 5

I understand. I'll review the help topic.
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2021, Yet Another Forum.NET
This page was generated in 0.202 seconds.