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.
Okay...by 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:
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.
Okay...by 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.
magickImage.PreserveColorType();
// For better or worse: Change color type, space and profile.
magickImage.BitDepth(8);
magickImage.ColorType = ColorType.TrueColor;
magickImage.ColorSpace = ImageMagick.ColorSpace.sRGB;
if (magickImage.GetColorProfile().ColorSpace != ImageMagick.ColorSpace.sRGB)
{
ColorProfile targetProfile = ColorProfile.SRGB;
magickImage.AddProfile(targetProfile);
}
// Add the image to the collection.
collection.Add(magickImage);
// Create psd file.
if (File.Exists(outputImagePath)) File.Delete(outputImagePath);
collection.Write(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.