This project has moved and is read-only. For the latest updates, please go here.

Convert rgb byte array to cymk byte array

May 10, 2016 at 9:01 PM
Hello, New to magick.NET and hoping to utilize it to convert a rgb pdf to a cymk pdf.

What I need Magick.NET for is to convert a rgb byte array into a cymk byte array

Any guidance?

Here is my code so far
 Protected Shared Function TEST(ByVal imageArray As Byte(), ByVal rec As Rectangle) As Byte()
            Dim settings As New MagickReadSettings()
            settings.Width = rec.Width
            settings.Height = rec.Height
            settings.ColorSpace = ColorSpace.CMYK


            ' Read image from file
            Using image As New MagickImage(imageArray, settings)
                image.Format = MagickFormat.Cmyk
                ' Create byte array that contains a jpeg file
                Dim data As Byte() = image.ToByteArray()
                Return data
            End Using
        End Function
Any help is appreciated.
May 11, 2016 at 6:13 AM
I think you should look for another tool to do this. PDF is a vector file format and will be changed to a raster format when read. Writing it back will result in a much bigger file with a lower quality document.
May 11, 2016 at 2:56 PM
dlemstra wrote:
I think you should look for another tool to do this. PDF is a vector file format and will be changed to a raster format when read. Writing it back will result in a much bigger file with a lower quality document.
I appreciate your response. My boss still wants me to make an attempt using magick. Am I headed in the right direction to get this to work so we can see the lower quality result?
May 11, 2016 at 8:13 PM
It might be better to use the TransformColorSpace of MagickImage to change the image from RGB to CMYK:
image.TransformColorSpace(ColorProfile.SRGB, ColorProfile.USWebCoatedSWOP);
And if your PDF file contains multiple pages you should use the MagickImageCollection instead and then call TransformColorSpace on each of the images in your collection. And you might want to change 'settings.Density' to a DPI of 300 to get an image with a better quality.