Aspose.word有的图片解析出来的是黑色的

图片黑色.jpg (33.1 KB)
练习文档-图片识别.docx (516.1 KB)
获取到的图片有的是黑色的,没有正常解析出来,请帮看看问题主要代码如下:

<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-words</artifactId>
    <version>23.12</version>
    </dependency>
<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-imaging</artifactId>
    <version>23.3</version>
</dependency>
private void getImage(com.aspose.words.Document document ){
        NodeCollection<Shape> shapes = document.getChildNodes(NodeType.SHAPE, true);
        for (Shape shape : shapes) {

            try {
                if (!shape.hasImage()) {
                    continue;
                }
                ImageData imageData =  shape.getImageData();
                    InputStream originalImage = new ByteArrayInputStream(imageData.getImageBytes());
                    try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {

                        Thumbnails.of(originalImage)
                                .outputFormat("JPEG")
                                .scale(0.9f)
                                .outputQuality(0.5)
                                .toOutputStream(outputStream);
                        InputStream img =  new ByteArrayInputStream(outputStream.toByteArray());
                        // to save image
                    }

            } catch (Exception e) {
                log.error("图片解析异常",  e);
            }
        }
    }

@zchong 这似乎是Thumbnailator库的一个错误。如果您将文件扩展名从“.docx”更改为“.zip”并解压缩文件,您可以在“练习文档-图片识别\word\media“folder. ”Image4.png“和”Image5.png“具有透明背景,这会导致问题。您可以使用简单的代码来检查问题:

Thumbnails.of(new File("image4.png"))
        .outputFormat("JPEG")
        .scale(0.9f)
        .outputQuality(0.5)
        .toFile(new File("image4.jpeg"));

以下是有关问题的链接: