We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How can I determine the crop information of an image in visitDrawingMLStart() and visitShape()

My goal is to save an image to the disk (actually get an InputStream) to an image that represents exactly what the user sees in MS Word. It appears that this is possible if the image is just a shape and is visited via visitShape(Shape shape). In this case, I can do the following:

ImageData imageData = shape.getImageData();

That allows me to manipulate the original image such that I can save only the portion of the image that the user can see in MS Word (without changing the crop).

There are another class of images that are visited via visitDrawingMLStart(DrawingML drawing). In this case, I can do the following:

DrawingMLImageData imageData = drawing.getImageData();
Unfortunately, the DrawingMLImageData type does not include any crop methods such that I can determine where the cropped area of the image is. Therefore, it is not possible for me to get an InputStream to the bytes that represent the cropped region.

Thank you for any assistance!

Hi Chase,

Thanks for your inquiry. Please try running the following code snippet to get both the original and the cropped images (the same should be true for DrawingML nodes):
Document doc = new Document(“C:\Temp\crop.doc”);
Shape shape = (Shape) doc.selectNodes("//Shape").get(0);
// to get the cropped shape
shape.getShapeRenderer().save(“C:\Temp\outCropped.png”, new ImageSaveOptions(SaveFormat.PNG));
//to get the actual image
I hope, this helps.

Best regards,

Hey Awais,

Thank you for the help! This is exactly what I was looking for!