问题描述:我用新的背景图像更换PSD文件中的背景图像,更换失败,代码和输入如下
输入背景图像:
1.jpg (138.0 KB)
替换后用PSD文件导出的图像为:
out_3_1.jpg (227.5 KB)
代码:
String path = “…/test_3.psd”;
String imgPath = “…/1.png”;
String desPath = “…/out_3_2.jpg”;
Image image =Image.load(path);
PsdImage psdImage = (PsdImage) image;
String layerName = "图层 760";
for(int i=0; i < psdImage.getLayers().length; i++ ) {
String name = psdImage.getLayers()[i].getDisplayName();
if (name.equals(layerName)) {
SmartObjectLayer smartLayer = (SmartObjectLayer)psdImage.getLayers()[i];
smartLayer.replaceContents(imgPath);
smartLayer.updateModifiedContent();
}
}
psdImage.save(desPath,new JpegOptions());