poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Fisher <dfis...@jmlafferty.com>
Subject Re: HSSFPicture:getImageDimension fails under eclipse works under AIX
Date Tue, 11 Nov 2008 22:26:25 GMT

Maybe, you'll need to be "headless"


Yegor has been through this pain. I suggest you try the following  

Create an Excel document with an image in the size you want on Windows.

Open the same file on the Mac. Its aspect ratio will be squashed like  
a standard TV expanded onto HDTV. There are all types of effects the  
most important being the size of the default font in the Excel  
Application which is NOT a document setting.

Play with WIndows dpi and see things change.

FYI there is an even sicker trouble with sizing Escher font characters  
within a drawing. Scaling can lead to results you don't expect.

Microsoft in its wisdom only supports font characters in discrete  
pixel sizes in Excel. Scaling is rounded. And then layout is wrong on  
the Mac due to aspect ratio.

Powerpoint also gives goofy effects with device independent and  
dependent display that differs between Mac and Windows and Excel.

Yes, I wish resize was better, you are free to try. That said I've had  
Yegor spend time on these issues several times over the past few years.


On Nov 11, 2008, at 3:28 PM, Rob Y wrote:

> 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: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org

To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org

View raw message