HSSFPicture.resize() uses an internal getImageDimension() method, which uses
various objects from javax.imageio and java.awt.image. When I call this
method from my AIX C app (via a JNI wrapper), it works. But to debug my
wrapper, I run it under Eclipse on Windows. When I call getImageDimension
there, it throws an AritmeticException at the size.width calculation below:
int[] dpi = getResolution(r);
size.width = img.getWidth()*96/dpi[0];
it turns out that dpi comes back from getResolution as 0, so you get a
divide-by-zero exception. Is there a problem using javax.imageio or
java.awt.image under eclipse? I know eclipse doesn't use AWT normally, but
I'm not getting an 'unable to locate class' type of error.
Thanks,
Rob
Here's the whole method:
public Dimension getImageDimension(){
EscherBSERecord bse =
patriarch.sheet.book.getBSERecord(pictureIndex);
byte[] data = bse.getBlipRecord().getPicturedata();
int type = bse.getBlipTypeWin32();
Dimension size = new Dimension();
switch (type){
//we can calculate the preferred size only for JPEG and PNG
//other formats like WMF, EMF and PICT are not supported in Java
case HSSFWorkbook.PICTURE_TYPE_JPEG:
case HSSFWorkbook.PICTURE_TYPE_PNG:
case HSSFWorkbook.PICTURE_TYPE_DIB:
try {
//read the image using javax.imageio.*
ImageInputStream iis = ImageIO.createImageInputStream(
new ByteArrayInputStream(data) );
Iterator i = ImageIO.getImageReaders( iis );
ImageReader r = (ImageReader) i.next();
r.setInput( iis );
BufferedImage img = r.read(0);
int[] dpi = getResolution(r);
size.width = img.getWidth()*96/dpi[0];
size.height = img.getHeight()*96/dpi[1];
} catch (IOException e){
//silently return if ImageIO failed to read the image
log.log(POILogger.WARN, e);
}
break;
}
return size;
}
--
View this message in context:
http://www.nabble.com/HSSFPicture%3AgetImageDimension-fails-under-eclipse-works-under-AIX-tp20448425p20448425.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]