Aspose.Imaging如何把PSD文件中每层导出为单独的图片

作者:控件中国网   出处:控件中国网   2016-01-12 10:31:53   阅读:16

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.
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(sourceFileName))
{
 
    // Cast image object to PSD image
    var psdImage = (Aspose.Imaging.FileFormats.Psd.PsdImage)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);
    }
}
Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat