Hello,
I’m trying to convert TIFF images that have a RGB color profile to a CMYK color profile.
I’m using the code I found there: Converting RGB TIFF to CMYK TIFF with Aspose.Imaging 18.3 - DEV Community
And for the CMYK profile, I use the cmyk.icc I found there: https://github.com/aspose-imaging/Aspose.Imaging-for-.NET/tree/master/Examples/Data/ModifyingAndConvertingImages/cmyk.icc
The issue when I run the code is I’m getting an error message on the Save() method to a memoryStream. See below for my code and the error message
Any idea what I could be doing wrong?
Thank you
Code
//Load the output color profile
MemoryStream cmykProfile; string cmykProfilePath = "cmyk.icc";
using (FileStream stream = new FileStream(cmykProfilePath, FileMode.Open))
{
byte[] bytes = new byte[stream.Length];
stream.Read(bytes, 0, (int)stream.Length);
cmykProfile = new MemoryStream(bytes);
}
//Set up save file format parameters
TiffOptions options = new TiffOptions(TiffExpectedFormat.TiffLzwCmyk);
options.IccProfile = cmykProfile;
//Load and save
File.WriteAllBytes($"C:\\Temp\\{image.FileName}_BeforeTiffConversion.{image.OutputFormat}", image.ConvertedImageContent);
var imageLoadingStream = new MemoryStream(image.ConvertedImageContent);
MemoryStream imageSavingStream = new();
using (Image conversionImage = Image.Load(imageLoadingStream))
{
try
{
conversionImage.Save(imageSavingStream, options);
}
catch (Exception ex)
{
logger.LogError(ex, "Error converting image to CMYK");
}
}
image.ConvertedImageContent = imageSavingStream.ToArray();
Error message
Aspose.Imaging.CoreExceptions.ImageSaveException: ‘Image export failed.’
#=z$cphyxuulJJe2MJAzFnuCWK4Rx7gPq1qWECL0gI=: Exception of type ‘#=z$cphyxuulJJe2MJAzFnuCWK4Rx7gPq1qWECL0gI=’ was thrown.