Aspose.Imaging是一款多图片格式处理和转换控件,可以同时用于Java和.NET下,利用该控件提供的API不仅可以处理矢量图片,也可以处理光栅图片,这篇文章主要介绍怎么对Photoshop生成的PSD文件进行处理,由于PSD文件经常是由很多层组成,客户有时需要把每一层都导出为单独的图片,
Aspose.Imaging可以帮助开发人员快速实现该功能,具体可以参考下面详细的代码:
/string sourceFileName = @"source.psd";
// Create an instance of Image class and load PSD file as image.
{
// Cast image object to PSD image
// Create an instance of PngOptions class
var pngOptions = new PngOptions();
pngOptions.ColorType =
Aspose.Imaging.FileFormats.Png.PngColorType.TruecolorWithAlpha;
// Loop through the list of layers
for (int i = 0; i < psdImage.Layers.Length; i++)
{
// convert and save the layer to PNG file format.
psdImage.Layers[i].Save(string.Format("layer{0}.png", i + 1), pngOptions);
}
}