1 - Please use the Shape.ImageData.ImageType property.
2 - Please try running the following code snippet to get both the original and 'as displayed in MS Word' images.
Document doc = new Document("C:\\Temp\\input.doc");
Shape shape = (Shape) doc.selectNodes("//Shape").get(0);// to get the cropped/displayed shape
shape.getShapeRenderer().save("C:\\Temp\\outCropped.png",new ImageSaveOptions(SaveFormat.PNG));//to get the actual image
shape.getImageData().save("C:\\Temp\\outOriginal.png");
1. Shape.ImageData.ImageType = EMF (see my example) - it meansnothing to me, I need to know of type of raw (source) data - bitmap (e.g. PNG) or vector graphics. Is it possible?
2. I need to get the image in form before inserted in the document with source resolution and size.
shape.getImageData().save(…) saves EMF data, not actual image.
1 - I think, you can meet this requirement by using Aspose.Imaging for Java. Please see the following method:
com.aspose.imaging.Image.getFileFormat()
You can pass String or InputStream as input parameter to this method. This method detects the image format regardless of the file extension. Hope, this helps.
2 - Can you please elaborate what do you mean when saying that you need to get the image in form before inserted in the document with source resolution and size? Do any of the following methods work for you?
shape.getShapeRenderer().save
shape.getImageData().save
If not, what method would you like to see in Aspose.Words API? Please provide complete signature of expected method i.e. return type and input parameters etc.
shape.getImageData().save(…) saves the EMF data, but I need the image.
shape.getShapeRenderer().save(…) saves the cropped image, but I need the full size image.
Let me show you an example of existing shape again:
shapeType=Image
hasImage=true
imageType=Emf
hasChart=false
fileExtension=.emf
isOle=false
shape size(px)=467.6967716535433 x 244.8
image size(pt)=1534.3360613334207 x 804.1978712566225
image size(px)=1534 x 804
resolution=71.9842300415039 x 71.98228454589844
So I need to get the image with size 1534x804 px, but using shape.getShapeRenderer().save(…) I get the image with size 468x245 px (shape size in the document).
Right click on picture and choose “Save as Picture”. Save it
What size do you get in this case?
I found that MS Word 2016 generated picture has a lesser size same as ImageData.Save returns. This seems an expected behavior as the original size information seems not present in Document itself.