1.源psd文件:
009酒店餐饮-餐饮甜品-五一劳动节 竖版.zip (5.2 MB)
2.源代码:
public static void main(String[] args) throws FileNotFoundException
{
try {
License license = new License();
String licFileDir = “E:\mysite\openproj\Aspose.PSD-for-Java\Examples\src\main\resources\Lic\Aspose.Total.Product.Family.lic”;
license.setLicense(licFileDir);
String dataDir = "E:\\mysite\\openproj\\Aspose.PSD-for-Java\\Examples\\src\\main\\resources\\PSD\\";
Cache.setCacheFolder(dataDir);
// Set cache on disk.
Cache.setCacheType(CacheType.CacheInMemoryOnly);
// The default cache max value is 0, which means that there is no upper limit
Cache.setMaxMemoryForCache(1073741824); // 1 gigabyte
// We do not recommend that you change the following property because it may greatly affect performance
Cache.setExactReallocateOnly(false);
String sourceFileName = dataDir+ "009酒店餐饮-餐饮甜品-五一劳动节 竖版.psd";
String exportPath = dataDir+ "009酒店餐饮-餐饮甜品-五一劳动节 竖版New.png";
PsdLoadOptions loadOptions = new PsdLoadOptions();
loadOptions.setLoadEffectsResource(true);
long startTime = System.currentTimeMillis(); //获取开始时间
PsdImage image =(PsdImage) Image.load(sourceFileName,loadOptions);
PngOptions options = new PngOptions();
//options.setCompressionLevel(Compression.NONE.getValue());
options.setColorType(PngColorType.TruecolorWithAlpha);
Boolean success = false;
image.save(exportPath,options);
success = true;
long endTime = System.currentTimeMillis(); //获取结束时间
//image.dispose();
System.out.println("程序运行时间:" + (endTime - startTime)/1000 + "s"); //输出程序运行时间
} catch (Exception e) {
e.printStackTrace();
log.error("message:" + e.getMessage());
System.out.println("e:" + e.getMessage());
}
}
3.实际输出:
009酒店餐饮-餐饮甜品-五一劳动节 竖版New.jpg (546.8 KB)
4.期望结果:
009酒店餐饮-餐饮甜品-五一劳动节 竖版expect.jpg (564.6 KB)