1.问题场景:psd转图片,整图效果有渐变,但单图层转图片时,确没有了效果。
2.源代码:
public static void main(String[] args) throws FileNotFoundException {
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\”;
String sourceFileName = dataDir + “nvwangJy.psd”;
String exportPath = dataDir + “mudassir3TextUpdateResult.png”;
PsdLoadOptions loadOptions = new PsdLoadOptions();
//Try this
loadOptions.setLoadEffectsResource(true);
PsdImage image=(PsdImage) Image.load(sourceFileName,loadOptions);
PngOptions options = new PngOptions();
options.setColorType(PngColorType.TruecolorWithAlpha);
for(int i=0; i < image.getLayers().length; i++ )
{
if (i == 10 && image.getLayers()[i] instanceof TextLayer)
{
TextLayer textLayer = (TextLayer)image.getLayers()[i];
Point leftTopCoordinate = new Point();
leftTopCoordinate.setX(textLayer.getLeft());
leftTopCoordinate.setY(textLayer.getTop());
textLayer.updateText("你的", leftTopCoordinate, ((TextLayer)textLayer).getFont().getSize(), ((TextLayer)textLayer).getTextColor());
String pngExportPath = dataDir+ "nvwangNewTextLayer444" + i + ".png";
textLayer.save(pngExportPath, options);
}
}
image.save(exportPath,options);
}
3.实际输出:
整图效果:mudassir3TextUpdateResult.jpg (293.0 KB)
单图层效果:
mudassir3TextUpdateResult.jpg (293.0 KB)
4.期望结果:
希望单图层转图片时,也保留其效果(渐变)
5.源psd文件:
nvwangJy.zip (2.6 MB)