This project has moved. For the latest updates, please go here.

Save grayscaled image as truecolor PSD file

Mar 10, 2016 at 9:57 AM
I am currently experiencing some problems when saving images containing only gray colors to truecolor PSD files.
An example image can be found here.
This image has a valid sRGB color profile and is saved with RGB color space. So far so good. But when saving it as a PSD file via Magic.NET the color space is automatically converted to grayscale. This then leads to the sRGB icc profile being invalid. I searched in multiple forums to find out two things:

-First: I am not the only one having problems with this.
-Second: This is by design. design it is then...but there should be a way to force the resulting color space. I then found this post, which explained a lot, but ultimately failed in helping me.

This is my test code:
public static void SavePsd()
    string inputImagePath = @"C:\not_so_gray_at_all.jpg";
    string outputImagePath = @"C:\totally_gray_now.psd";
    MagickReadSettings readSettings = new MagickReadSettings() { ColorSpace = ImageMagick.ColorSpace.sRGB };
    using (MagickImageCollection collection = new MagickImageCollection())
    using (MagickImage magickImage = new MagickImage(inputImagePath, readSettings))
        // Set format to psd.
        magickImage.Format = MagickFormat.Psd;

        // Do NOT change the color type.
        // For better or worse: Change color type, space and profile.
        magickImage.ColorType = ColorType.TrueColor;
        magickImage.ColorSpace = ImageMagick.ColorSpace.sRGB;
        if (magickImage.GetColorProfile().ColorSpace != ImageMagick.ColorSpace.sRGB)
            ColorProfile targetProfile = ColorProfile.SRGB;

        // Add the image to the collection.

        // Create psd file.
        if (File.Exists(outputImagePath)) File.Delete(outputImagePath);
So I really tried telling Magic.NET to stick with sRGB but to no avail. Am I missing some property or should I use another method? Using the debugger I found out, that the ReadMask and the WriteMask of Magick.NET are both set to 8bit grayscale (here). But trying to override those properties was fruitless.
Mar 12, 2016 at 6:46 AM
The Read/Write Masks properties can be used to hide/lock a specific part of an image and are not related to your issue.

It turns out that I forgot to add something to the PreserveColorType method. And I also had to fix something in my unit test that should have detected this. In the next version of Magick.NET your issue will be resolved.
Mar 12, 2016 at 4:26 PM
That are great news. I will wait until the new version has been released and will test it then. Thank you very much again for your relentless effort.