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

Free Support Forum - aspose.com

Best method to get Image size?

Dear Team,

I am using aspose latest version for document conversion . I am trying to get image size by below method but its not working for all cases. Please suggest me the correct way to get image size .
shapeNode.getHeight ();

( or )

ImageData image = shapeNode.getImageData ( );
ImageSize size = image.getImageSize( );
size.getHeightPixels( );

Regards,
AnbuChezhian.S

Hello

Thanks for your inquiry. Could you please attach the document you are getting problem with? I will check it on my side and provide you more information.

Best regards,

Dear Andrey,

Thanks for the reply . I attached doc with this. Please tell me which is correct method to get exact width and height.

Thanks
Anbu

Hello,


Thanks for your request. The second method is correct.

Best regards,

Hello Anbu,

Thank you for additional information. The images inside your document are DrawingML objects. Please see the following link to learn how to work with DrawingML using Aspose.Words:

http://www.aspose.com/documentation/java-components/aspose.words-for-java/com/aspose/words/drawingml.html

Use the DrawingML.ImageData property to work with image inside a DrawingML picture:

http://www.aspose.com/documentation/java-components/aspose.words-for-java/com/aspose/words/drawingmlimagedata.html

Please see the following code:

Document doc = new Document("C:\\Temp\\saleslist.docx");

Node[] dmls = doc.getChildNodes(NodeType.DRAWING_ML, true).toArray();

// Loop through all images

for(int i=0; i<dmls.length; i++)

{

DrawingML dml = (DrawingML)dmls[i];

if(dml.hasImage())

{

DrawingMLImageData image = dml.getImageData();

ImageSize size = image.getImageSize( );

System.out.println("Height= " + size.getHeightPixels());

System.out.println("Width= " + size.getWidthPixels());

System.out.println("-------------");

}

}

Best regards,

Thanks for the reply. I have attached document containing Image with this . I have tried above method to get the size of image, but it is giving the original image size not the modified image size .


Code :
System.out.println(“Shape height:” + shapeNode.getHeight() + " Width : " + shapeNode.getWidth() );
ImageData image = shapeNode.getImageData();
ImageSize size = image.getImageSize();
System.out.println(“Image height:” + size.getHeightPixels() + " Width : " + size.getWidthPixels() );

Output :

Shape height : 121.53599999999999 Width : 162.048
Image height : 768 Width : 1024


Thanks

Hi

Thanks for your request. As I can see, Aspose.Words returns correct values. Please see the attached screenshot.

Here is code I used for testing and output:

Document doc = new Document("C:\\Temp\\image.doc");

Shape shapeNode = (Shape)doc.getChild(NodeType.SHAPE, 0, true);

System.out.println("Shape height:" + shapeNode.getHeight() + "pt; Width : " + shapeNode.getWidth() + "pt");

ImageData image = shapeNode.getImageData();

ImageSize size = image.getImageSize();

System.out.println("Image height:" + size.getHeightPoints() + "pt; Width : " + size.getWidthPoints() + "pt");

Shape height:121.53599999999999pt; Width : 162.048pt

Image height:576.0pt; Width : 768.0pt

As you can see, Aspose.Words returns the same values as MS Word.

Best regards,