Hi,
Thank you for the fix - I can confirm that the code block that has been provided is now working correctly.
Unfortunately, that code block was just a tiny sample with the isolated problem and not the full scope of what we need to achieve, so we’re still running into problems with this.
Specifically, we need to edit/manipulate a few pixels from the PSD images/layers, so we load the pixels, edit them and save them back to the image.
Unfortunately, regardless of which method we use, CMYK images get the exact same color distortion that has been fixed on PSDNET-1583.
Here’s a code sample with a few attempts
private static void Main(string[] args)
{
new Aspose.PSD.License().SetLicense("../../../Aspose.PSD.NET.xml");
string canyon = "../../../canyon.psd";
string apple = "../../../apple.psd";
//Fixed
LoadAndSave(canyon);
LoadAndSave(apple);
//Not working correctly
SavePixels(canyon);
SavePixels(apple);
//Not working correctly
SavePixelsCMYK(canyon);
SavePixelsCMYK(apple);
//Not working correctly
SavePixelsCMYKAndForceMode(canyon);
SavePixelsCMYKAndForceMode(apple);
//Not working correctly
SavePixelsCMYKObsolete(canyon);
SavePixelsCMYKObsolete(apple);
}
private static void LoadAndSave(string path)
{
string newPath = path.Replace(Path.GetExtension(path), " - LoadAndSave" + Path.GetExtension(path));
using (Aspose.PSD.FileFormats.Psd.PsdImage image = (Aspose.PSD.FileFormats.Psd.PsdImage)Aspose.PSD.Image.Load(path))
{
image.Save(newPath, true);
}
}
private static void SavePixels(string path)
{
string newPath = path.Replace(Path.GetExtension(path), " - SavePixels" + Path.GetExtension(path));
using (Aspose.PSD.FileFormats.Psd.PsdImage image = (Aspose.PSD.FileFormats.Psd.PsdImage)Aspose.PSD.Image.Load(path))
{
foreach (var frame in image.Layers)
{
var pixels = frame.LoadPixels(new Aspose.PSD.Rectangle(0, 0, frame.Width, frame.Height));
frame.SavePixels(new Aspose.PSD.Rectangle(0, 0, frame.Width, frame.Height), pixels);
}
image.Save(newPath, true);
}
}
private static void SavePixelsCMYK(string path)
{
string newPath = path.Replace(Path.GetExtension(path), " - SavePixelsCMYK" + Path.GetExtension(path));
using (Aspose.PSD.FileFormats.Psd.PsdImage image = (Aspose.PSD.FileFormats.Psd.PsdImage)Aspose.PSD.Image.Load(path))
{
foreach (var frame in image.Layers)
{
var pixels = frame.LoadCmyk32Pixels(new Aspose.PSD.Rectangle(0, 0, frame.Width, frame.Height));
frame.SaveCmyk32Pixels(new Aspose.PSD.Rectangle(0, 0, frame.Width, frame.Height), pixels);
}
image.Save(newPath, true);
}
}
private static void SavePixelsCMYKAndForceMode(string path)
{
string newPath = path.Replace(Path.GetExtension(path), " - SavePixelsCMYKAndForceMode" + Path.GetExtension(path));
using (Aspose.PSD.FileFormats.Psd.PsdImage image = (Aspose.PSD.FileFormats.Psd.PsdImage)Aspose.PSD.Image.Load(path))
{
foreach (var frame in image.Layers)
{
var pixels = frame.LoadCmyk32Pixels(new Aspose.PSD.Rectangle(0, 0, frame.Width, frame.Height));
frame.SaveCmyk32Pixels(new Aspose.PSD.Rectangle(0, 0, frame.Width, frame.Height), pixels);
}
File.Delete(newPath);
image.Save(newPath, new Aspose.PSD.ImageOptions.PsdOptions() { ColorMode = Aspose.PSD.FileFormats.Psd.ColorModes.Cmyk });
}
}
private static void SavePixelsCMYKObsolete(string path)
{
string newPath = path.Replace(Path.GetExtension(path), " - SavePixelsCMYKObsolete" + Path.GetExtension(path));
using (Aspose.PSD.FileFormats.Psd.PsdImage image = (Aspose.PSD.FileFormats.Psd.PsdImage)Aspose.PSD.Image.Load(path))
{
foreach (var frame in image.Layers)
{
var pixels = frame.LoadCmykPixels(new Aspose.PSD.Rectangle(0, 0, frame.Width, frame.Height));
frame.SaveCmykPixels(new Aspose.PSD.Rectangle(0, 0, frame.Width, frame.Height), pixels);
}
image.Save(newPath, true);
}
}
From the methods above, only the “LoadAndSave” is working correctly - this doesn’t do anything to the image, however - it’s just the Load/Save operations.
I’m sharing both images from these tests:
https://drive.google.com/file/d/1zYAbUG9in4lGQzD7MFtdul1DdncowBug/view?usp=sharing
Can you please check the code and let me know if there’s anything that can be done on my end to work around this, or if there’s anything that can be changed on Aspose.PSD?
To clarify, the goal is to persist the file as-is, so we cannot use a workaround that manipulates the image type (such as converting it to PNG).
Thank you