Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in compressed image example on official website #102

Open
JLinCode opened this issue Sep 6, 2023 · 3 comments
Open

Error in compressed image example on official website #102

JLinCode opened this issue Sep 6, 2023 · 3 comments

Comments

@JLinCode
Copy link

JLinCode commented Sep 6, 2023

https://products.aspose.com/words/zh/java/compress/

doc.cleanup();

NodeCollection nodes = doc.getChildNodes(NodeType.SHAPE, true);
for (Shape shape : (Iterable) nodes)
{
    if (shape.isImage())
    {
// 由开发人员选择用于图像压缩的库。
        BufferedImage image = ImageIO.read(shape.getImageData().toStream());

   
// 压缩图像并将其设置回形状。
        shape.getImageData().setImage("yourCompressedImage");
    }
}

OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
saveOptions.setCompressionLevel(CompressionLevel.MAXIMUM);

doc.save("Output.docx", saveOptions);

In this example, using this code to report an error
Required type: Object
Provided: Shape

截图20230906181322
c6b63a4df7.png…]()

my maven

            <groupId>com.aspose</groupId>
            <artifactId>aspose-words</artifactId>
            <version>22.11</version>
            <classifier>jdk17</classifier>
        </dependency>
        <dependency>
            <groupId>com.aspose</groupId>
            <artifactId>aspose-words</artifactId>
            <version>22.11</version>
            <classifier>javadoc</classifier>
        </dependency>
@aspose-words-gists
Copy link

aspose-words-gists commented Sep 6, 2023

@pubil Thanks for notice this. Just change (Iterable) nodes to (Iterable<Shape>) nodes. We will fix it.

@JLinCode
Copy link
Author

JLinCode commented Sep 7, 2023

@pubil Thanks for notice this. Just change (Iterable) nodes to (Iterable<Shape>) nodes. We will fix it.

Can you provide a detailed image compression algorithm

@AlexNosk
Copy link

AlexNosk commented Sep 9, 2023

@pubil Images compression is out of Aspose.Words scope. Using Aspose.Words you can extract the original image bytes from the shape, then use some third party tool to compress the image and then using Aspose.Words set the compressed image to the shape.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants