You are correct. I get the original image size from the image data. But I also 
get the original data by using the anchor. And I need the size that user would 
see in Excel since the image is resized there. Here is some code I used. Sorry 
for the length of it. Everything I use from the picture, getAnchor, 
getPreferredSize, get... Returns the original size of the image, not the scaled 
one.

// Get the drawings
HSSFSheet sheet

HSSFPatriarch patriarch = sheet.getDrawingPatriarch();
        if (patriarch != null) {

                // Loop through the objects
                for (HSSFShape shape : patriarch.getChildren()) {
                        if (shape instanceof HSSFPicture) {
                                HSSFPicture picture = (HSSFPicture)shape;

                                try {

                                        // Read it as a picture
                                        BufferedImage bufferedImage = 
ImageIO.read(newByteArrayInputStream(picture.getPictureData().getData()));

                                        if (bufferedImage != null) {

                                                // Create a new report image
                                                ReportImage rImage = new 
ReportImage(reportSheet, bufferedImage);

                                                // Successfully read the image, 
get the position and size
                                                HSSFClientAnchor anchor = 
picture.getPreferredSize();

                                                // Save the offset and the 
position
                                                
rImage.setCol1Index(anchor.getCol1());
                                                
rImage.setCol2Index(anchor.getCol2());
                                                
rImage.setRow1Index(anchor.getRow1());
                                                
rImage.setRow2Index(anchor.getRow2());

                                                        
rImage.setCol1Offset(excelMetrics.getImageXOffset(anchor.getDx1(), sheet, 
anchor.getCol1()));
                                                        
rImage.setCol2Offset(excelMetrics.getImageXOffset(anchor.getDx2(), sheet, 
anchor.getCol2()));
                                                        
rImage.setRow1Offset(excelMetrics.getImageYOffset(anchor.getDy1(), sheet,
                                                                        
sheet.getRow(anchor.getRow1())));
                                                        
rImage.setRow2Offset(excelMetrics.getImageYOffset(anchor.getDy2(), sheet,
                                                                        
sheet.getRow(anchor.getRow2())));

-----Original Message-----
From: Mark Beardsley [mailto:[email protected]] 
Sent: 21. maaliskuuta 2012 17:47
To: [email protected]
Subject: RE: Excel image sizes

Must admit to being confused here. Are you trying to work out the size of the 
image the user would see if they were viewing the workbook using Excel? If not, 
can you explain a little more please?

--
View this message in context: 
http://apache-poi.1045710.n5.nabble.com/Excel-image-sizes-tp5582506p5583328.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional 
commands, e-mail: [email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to