0

The "duplicate" question explains how to change RGB to CMYK for a single value. I need to change an Image object and you can't convert it pixel by pixel, because you need a Bitmap object for it. If I change the Image object to Bitmap it's already converted, but with bad quality.

I have been using the same resize method for jpg images for ages, but today I noticed that some images have very bad quality.

        var newImage = new Bitmap(width, height);
        using (Graphics gr = Graphics.FromImage(newImage))
        {
            gr.SmoothingMode = SmoothingMode.HighQuality;
            gr.InterpolationMode = InterpolationMode.HighQualityBicubic;
            gr.PixelOffsetMode = PixelOffsetMode.HighQuality;
            gr.DrawImage(image, new Rectangle(0, 0, width, height));
        }

        //return image;
        return newImage;

Keep in mind that i'm not resizing anything at this point. If i return image the quality is like the original and if I return newImage the colors are very dull.

When you open the "bad" image in Photoshop, the image has a CMYK mode. If I change it to RGB in Photoshop and try again the colors stay the same.

I can detect the CMYK in C#, but I have no idea on how to alter the newImage object to keep the colors correct.

I tried to set the palette of newImage to the palette of image, but this throws an invalid parameter exception. I also tried to create the bitmap directly from the original with new Bitmap(image, new Size(width, height)); but this doesnt change anything.

I also tried to load the Graphics gr directly from the original image with Graphics gr = Graphics.FromImage(image) but this throws an Out of memory exception.

Example images are smaller then the original, but you can still see the quality difference.

CMYK RGB

How can I change CMYK to RGB in c# without quality loss?

Hugo Delsing
  • 13,803
  • 5
  • 45
  • 72
  • Possible duplicate of [Convert RGB color to CMYK?](http://stackoverflow.com/questions/2426432/convert-rgb-color-to-cmyk) – Leon Husmann Dec 05 '16 at 14:07
  • *"When you open the "bad" image in Photoshop, the image has a CMYK mode."* No, this doesn't make any sense. These are bitmap images. Bitmaps are never CMYK based, at least not as GDI+ defines bitmaps. – Cody Gray - on strike Dec 05 '16 at 14:09
  • @LeonHusmann I did find that post, but how do I apply the profile to an image? This is talking about single color values and not images. – Hugo Delsing Dec 05 '16 at 14:10
  • @HugoDelsing I would go over every pixel and apply the profile. – Leon Husmann Dec 05 '16 at 14:11
  • @CodyGray but still, If I use `return image` to get the original and save it, It shows as CMYK in photoshop. – Hugo Delsing Dec 05 '16 at 14:11
  • @LeonHusmann and How do you go over every pixel in an `Image` object? You need a `Bitmap` object and by then it's already converted. – Hugo Delsing Dec 05 '16 at 14:15
  • @HugoDelsing okay your right that is not possible, my fault. It seems that you may have to use an [external dll](https://social.msdn.microsoft.com/Forums/vstudio/en-US/f25f2e32-7226-4eca-9790-0ab8eea5ceda/create-cmyk-bitmap?forum=csharpgeneral). – Leon Husmann Dec 05 '16 at 14:19
  • @LeonHusmann The external DLL works indeed, but 800$ is a little much when we only need CMYK to RGB from that entire package. And that is just for one server and we have several. – Hugo Delsing Dec 05 '16 at 14:48

0 Answers0