I need to extract all the shapes from the table inserted in Doc file. Extracted shapes will be stored in PNG format in the database . while generating the report ,PNG Image should be placed in table cell but png image size will not be fit into the table cells size because PNG image is big in size.
Please let me know is it possible to reduce or remove white space from PNG image through aspose Api
Please find the attached input and output file. input.png (99.1 KB) output.png (78.8 KB)
I have written code but could not reach my requirement. Can you please help me out with java code (White space should not come while saving shape in PNG format).
public static BufferedImage crop(BufferedImage image) {
int width = image.getWidth();
int height = image.getHeight();
int top = height / 2;
int bottom = top;
int left = width / 2 ;
int right = left;
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
if (isFg(image.getRGB(x, y))){
top = Math.min(top, y);
bottom = Math.max(bottom, y);
left = Math.min(left, x);
right = Math.max(right, x);
}
}
}
return image.getSubimage(left, top, right - left, bottom - top);
}
I have written code to crop PNG image file .But it is not right way to reach my requirements(Quality of image will be gone and PNG file size will be large)
My requirement is while saving shape in PNG format I have to avoid white space , PNG file should contains only shape.
Please find the attached input and expected output file.
@Ramya_D I think, in your case it would be easier to use ShapeRenderer to render shapes to image. For example see the following code:
Document doc = new Document("C:\\Temp\\inputDoc.docx");
Iterable<Shape> shapes = (Iterable<Shape>)doc.getChildNodes(NodeType.SHAPE, true);
int i = 0;
for(Shape s : shapes)
{
s.getShapeRenderer().save("C:\\Temp\\out\\shape_"+i+".png", new ImageSaveOptions(SaveFormat.PNG));
i++;
}