I'm trying to write a function that will convert any TIFF into a set format acceptable by third party imaging software. The accepted formats are bitonal, 8-bit grayscale, and 24-bit RGB. In particular, I'd like to change 32-bit and 16-bit to the expected bit depths as well as non-RGB color spaces (specifically CMYK) to RGB. Here's my current code:
Am I going about this conversion the wrong way?
using (var frames = new MagickImageCollection(source))
{
var isCmyk = frames[0].ColorSpace == ColorSpace.CMYK;
int depth = frames[0].BitDepth();
if (depth == 32 || isCmyk)
{
foreach (var frame in frames)
{
frame.Format = MagickFormat.Tif;
frame.CompressionMethod = CompressionMethod.LZW;
frame.ColorSpace = ColorSpace.sRGB;
frame.Depth = 24;
}
frames.RePage();
return frames.ToByteArray();
}
else if (depth == 16)
{
foreach (var frame in frames)
{
frame.Format = MagickFormat.Tif;
frame.CompressionMethod = CompressionMethod.LZW;
frame.ColorSpace = ColorSpace.GRAY;
frame.Depth = 8;
}
frames.RePage();
return frames.ToByteArray();
}
else
{
return source;
}
}
From what I can tell, the problem is that the color space is always sRGB, and the bit depth is always 8, regardless of what I see in the detail properties of the image file.Am I going about this conversion the wrong way?