Hi There,
I have a trouble with the conversion result from PSD that contains SmartObject into image(PSD, JPG, PNG) formats. My PSD file contains a layer is smartObject with transform on the picture I draw on it some curves. Here is the sample data Google Drive
- Here is the structure of my PSD:
image.jpg (313.0 KB) - I would like to replace the content of SmartObject layer by another picture and keep the curves… but I don’t know why the result something like not apply the transform/formatted:
image.jpg (249.9 KB) - Then I try to open output.psd(above picture) and perform “Ctrl + T” => then result same as my expectation:
image.jpg (225.7 KB)
So could you please show me what I need to export the PSD or PNG file contain the transform(the curves in my case for example). Here is my code:
public static void processPSD(string psdPath, string imagePath)
{
PsdLoadOptions options = new PsdLoadOptions() { LoadEffectsResource = true };
using (PsdImage psd = (PsdImage)Aspose.PSD.Image.Load(psdPath, options))
{
for (int i = 0; i < psd.Layers.Length; i++)
{
var layer = psd.Layers[i];
SmartObjectLayer smartObjectLayer = layer as SmartObjectLayer;
if (smartObjectLayer != null)
{
using (Stream stream = new FileStream(imagePath, FileMode.Open, FileAccess.Read))
{
smartObjectLayer.Contents = getByteValue(stream);
smartObjectLayer.UpdateModifiedContent();
psd.SmartObjectProvider.UpdateAllModifiedContent();
}
}
}
psd.Save(@“C:\Users\Cuong\Desktop\out-psd.psd”);
psd.Save(@“C:\Users\Cuong\Desktop\out-jpg.jpeg”, new JpegOptions() { ColorType= JpegCompressionColorMode.Rgb, CompressionType = Aspose.PSD.FileFormats.Jpeg.JpegCompressionMode.Baseline});
}
}public static byte[] getByteValue(System.IO.Stream stream) { long originalPosition = 0; if (stream.CanSeek) { originalPosition = stream.Position; stream.Position = 0; } try { byte[] readBuffer = new byte[4096]; int totalBytesRead = 0; int bytesRead; while ((bytesRead = stream.Read(readBuffer, totalBytesRead, readBuffer.Length - totalBytesRead)) > 0) { totalBytesRead += bytesRead; if (totalBytesRead == readBuffer.Length) { int nextByte = stream.ReadByte(); if (nextByte != -1) { byte[] temp = new byte[readBuffer.Length * 2]; Buffer.BlockCopy(readBuffer, 0, temp, 0, readBuffer.Length); Buffer.SetByte(temp, totalBytesRead, (byte)nextByte); readBuffer = temp; totalBytesRead++; } } } byte[] buffer = readBuffer; if (readBuffer.Length != totalBytesRead) { buffer = new byte[totalBytesRead]; Buffer.BlockCopy(readBuffer, 0, buffer, 0, totalBytesRead); } return buffer; } finally { if (stream.CanSeek) { stream.Position = originalPosition; } } }
Note that I already research another method is smartObjectLayer.ReplaceContents("link_to_new_png_content.png");
but there NPE returns I don’t know why that, It happens when my SmartObjectLayer has transform curved.
Thank you for any suggestion.