Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active December 23, 2021 07:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/f4f1d5f10b7991a2c22e628dc19c5735 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/f4f1d5f10b7991a2c22e628dc19c5735 to your computer and use it in GitHub Desktop.
C# Convert PNG or JPG Image to PSD Programmatically in .NET
string fileName = "Sample.jpg";
// Initialize PsdImage class object
PsdImage image = new PsdImage(900, 700);
// Load input image into FileStream object
Stream stream = new FileStream(fileName, FileMode.Open);
Layer layer = null;
try
{
layer = new Layer(stream);
// Add input image as layer to PSD image
image.AddLayer(layer);
}
catch (Exception e)
{
if (layer != null)
{
layer.Dispose();
}
throw e;
}
// Convert JPG image to output PSD file
image.Save("JPGtoPSD.psd");
string fileName = "Sample.png";
// Initialize PsdImage class object
PsdImage image = new PsdImage(900, 700);
// Load input image into FileStream object
Stream stream = new FileStream(fileName, FileMode.Open);
Layer layer = null;
try
{
layer = new Layer(stream);
// Add input image as layer to PSD image
image.AddLayer(layer);
}
catch (Exception e)
{
if (layer != null)
{
layer.Dispose();
}
throw e;
}
// Convert PNG image to output PSD file
image.Save("PNGtoPSD.psd");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment