SmartObjectlayer对象的replaceContents方法来替换智能层图片,如果图片大小超出智能层的大小,那么替换之后的psd智能对象超出原有区域,智能对象也会变形?请问是需要设置些什么参数吗?
代码如下:
import java.io.IOException;
import com.aspose.psd.fileformats.psd.PsdImage;
import com.aspose.psd.fileformats.psd.layers.Layer;
import com.aspose.psd.fileformats.psd.layers.smartobjects.SmartObjectLayer;
public class Main {
public static void main(String[] args) throws IOException {
String psdPath = "Txue.psd";
String savePath = "new.psd";
String repleacePath = "tig.png";
PsdImage psd = (PsdImage) PsdImage.load(psdPath);
for (int i = 0; i < psd.getLayers().length; i++){
Layer layer = psd.getLayers()[i];
if (layer instanceof SmartObjectLayer){
SmartObjectLayer smart = (SmartObjectLayer)layer;
smart.replaceContents(repleacePath);
}
}
psd.save(savePath);
}
}
- tig.jpg (26.7 KB)
[nanshi.psd](https://xiaoyi-pro-test.oss-cn-shenzhen.aliyuncs.com/test/nanshi.psd?versionId=CAEQHRiBgIDr4oDI2hciIGUzMDMwMWJjYTIyYjQ3YTdiZTdlZjZlM2NlNGMxOTI0)。
[需要达到的效果psd](https://xiaoyi-pro-test.oss-cn-shenzhen.aliyuncs.com/test/Txue.psd?versionId=CAEQHRiBgMD.oIvI2hciIDJjNjdlYTFkMDkzOTQzYWRiYmFlMzVmNzAzNTIyYmQx)