The error message “The rectangle has no common processing area” typically indicates that the bounds of the layer group you are trying to export are invalid, meaning that the width or height of the bounds is less than or equal to zero. This can happen if the layer group is empty or if all layers within the group are hidden or have no visible content.
To resolve this issue, you should check the bounds of the layer group before attempting to save it. Here’s a modified version of your code that includes a check for valid bounds:
for (Layer layer : psdImage.getLayers()) {
if (layer instanceof LayerGroup) {
count++;
LayerGroup layerGroup = (LayerGroup) layer;
System.out.println("Layer Group Name: " + layerGroup.getName());
// Get the bounds of the layer group
Rectangle bounds = layerGroup.getBounds();
System.out.println("Bounds of Layer Group " + layerGroup.getName() + ": " + bounds);
// Check if the bounds are valid
if (bounds.getWidth() <= 0 || bounds.getHeight() <= 0) {
System.out.println("Skipping Layer Group " + layerGroup.getName() + " due to invalid bounds.");
continue; // Skip this layer group
}
// Create output path
fileNameNoExt = FilenameUtils.getBaseName(imageFilePath);
outPath = uploadPath + File.separator + fileNameNoExt + File.separator;
Path uploadPathPic = Paths.get(outPath);
if (!Files.exists(uploadPathPic)) {
Files.createDirectories(uploadPathPic);
}
// Save the layer group as PNG
String mergedPngPath = outPath + layerGroup.getName() + ".png";
layerGroup.save(mergedPngPath, new PngOptions());
System.out.println("Layer Group \"" + layerGroup.getName() + "\" has been saved as PNG: " + mergedPngPath);
}
}
In this code, if the bounds of the layer group are invalid, it will skip the export for that group and print a message indicating that it was skipped. This should help you avoid the error you encountered.
If you continue to experience issues, ensure that the layer group you are trying to export actually contains visible layers and that they are not hidden. You can also refer to the Aspose documentation on exporting PSD layer groups for more details on handling layer groups.
而且很奇怪,为什么我不能直接加载png图片呢?
报错信息:“Image loading failed. Cannot open an image. The image file format may be not supported at the moment.”
代码: RasterImage newContent = (RasterImage)com.aspose.psd.Image.load(“D:\J\Idea2024\IDEAProject\EnMingERP\python\file\TRF8502.png”);
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
@LiXinChen could you please provide the input PSD file, also it’s better to create new forum topic. In this case you’ll get the notification when it will be fixed
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.