如何使用Aspose.Imaging为PSD文件中的图层导入图片

作者:控件中国网   出处:控件中国网   2016-05-11 10:07:37   阅读:17

开发人员可以快速使用Aspose.Imaging for .NET提供的API为PSD文件中的图层导入各种图片,通过控件提供的Layer类里的DrawImage方法来添加或者导入图片到图层里,使用DrawImage方法时需要图片的位置以及图片值,具体可以参考下面的部分代码,开发人员可以从控件中国网上下载该产品的最新版本进行该功能的测试:
 
//Declare variables to store file paths for input and output.
string sourceFileName = "source.psd";
string outputFileName = "result.psd";
 
// Load a PSD file as an image and caste it into PsdImage
using (Aspose.Imaging.FileFormats.Psd.PsdImage image = (Aspose.Imaging.FileFormats.Psd.PsdImage)Aspose.Imaging.Image.Load
 
(sourceFileName))
{
     // Extract a layer from PSDImage
     Aspose.Imaging.FileFormats.Psd.Layers.Layer layer = image.Layers[1];
 
     // Load the image that is needed to be imported into the PSD file.
     string normalImagePath = "png_normal.png";
     using (RasterImage drawImage = (RasterImage)Aspose.Imaging.Image.Load(normalImagePath))
     {
           // Call DrawImage method of the Layer class and pass the image instance.
           layer.DrawImage(new Aspose.Imaging.Point(10, 10), drawImage);
     }
 
     //Save the results to output path.
     image.Save(outputFileName, new PsdOptions());
}
Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat