Learn how to add a new layer in a PSD using C# : https://blog.aspose.com/2022/08/11/add-new-layer-in-psd-using-csharp/
The following topics are covered in this article:
Learn how to add a new layer in a PSD using C# : https://blog.aspose.com/2022/08/11/add-new-layer-in-psd-using-csharp/
The following topics are covered in this article:
// This code example demonstrates how to create new layer from a PNG image in PSD image file. | |
string outputFilePath = @"C:\Files\PSD\PsdResult.psd"; | |
// Create a new PSD image | |
var image = new PsdImage(200, 200); | |
// Load a PNG image | |
string filePath = @"C:\Files\PSD\aspose_logo.png"; | |
var stream = new FileStream(filePath, FileMode.Open); | |
Layer layer = null; | |
try | |
{ | |
// Add layer to PSD | |
layer = new Layer(stream); | |
image.AddLayer(layer); | |
} | |
catch (Exception e) | |
{ | |
if (layer != null) | |
{ | |
layer.Dispose(); | |
} | |
throw e; | |
} | |
// Save PSD | |
image.Save(outputFilePath); |
// This code example demonstrates how to create new layers in PSD image file. | |
string sourceFileName = @"C:\Files\PSD\OneLayer.psd"; | |
string exportPath = @"C:\Files\PSD\OneLayerEdited.psd"; | |
// Load an existing PSD | |
var im = (PsdImage)Image.Load(sourceFileName); | |
// Preparing two int arrays | |
var data1 = new int[2500]; | |
var data2 = new int[2500]; | |
// Define rectangles | |
var rect1 = new Rectangle(0, 0, 50, 50); | |
var rect2 = new Rectangle(0, 0, 100, 25); | |
for (int i = 0; i < 2500; i++) | |
{ | |
data1[i] = -10000000; | |
data2[i] = -10000000; | |
} | |
// Add Layer 1 | |
var layer1 = im.AddRegularLayer(); | |
layer1.Left = 25; | |
layer1.Top = 25; | |
layer1.Right = 75; | |
layer1.Bottom = 75; | |
layer1.SaveArgb32Pixels(rect1, data1); | |
// Add Layer 2 | |
var layer2 = im.AddRegularLayer(); | |
layer2.Left = 25; | |
layer2.Top = 150; | |
layer2.Right = 125; | |
layer2.Bottom = 175; | |
layer2.SaveArgb32Pixels(rect2, data2); | |
// Save PSD | |
im.Save(exportPath, new PsdOptions()); |
// This code example demonstrates how to create new layers in PSD image file. | |
string sourceFileName = @"C:\Files\PSD\OneLayer.psd"; | |
string exportPath = @"C:\Files\PSD\TextLayer.psd"; | |
// Load an existing PSD | |
var im = (PsdImage)Image.Load(sourceFileName); | |
// Add a text layer | |
var layer1 = im.AddTextLayer("Hello", new Rectangle(0, 0, 120, 50)); | |
layer1.Left = 10; | |
layer1.Top = 25; | |
// Save PSD | |
im.Save(exportPath, new PsdOptions()); |