Return-Path: Delivered-To: apmail-poi-user-archive@www.apache.org Received: (qmail 5062 invoked from network); 11 Nov 2008 22:27:01 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 11 Nov 2008 22:27:01 -0000 Received: (qmail 35017 invoked by uid 500); 11 Nov 2008 22:27:07 -0000 Delivered-To: apmail-poi-user-archive@poi.apache.org Received: (qmail 35001 invoked by uid 500); 11 Nov 2008 22:27:07 -0000 Mailing-List: contact user-help@poi.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "POI Users List" Delivered-To: mailing list user@poi.apache.org Received: (qmail 34990 invoked by uid 99); 11 Nov 2008 22:27:07 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 11 Nov 2008 14:27:07 -0800 X-ASF-Spam-Status: No, hits=3.9 required=10.0 tests=DNS_FROM_RFC_DSN,SPF_HELO_PASS,SPF_NEUTRAL,WHOIS_MYPRIVREG X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [216.86.168.183] (HELO mxout-08.mxes.net) (216.86.168.183) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 11 Nov 2008 22:25:46 +0000 Received: from [192.168.1.104] (unknown [98.210.13.60]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by smtp.mxes.net (Postfix) with ESMTP id A2C0FD05A5 for ; Tue, 11 Nov 2008 17:26:27 -0500 (EST) Message-Id: From: David Fisher To: "POI Users List" In-Reply-To: <20448425.post@talk.nabble.com> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v929.2) Subject: Re: HSSFPicture:getImageDimension fails under eclipse works under AIX Date: Tue, 11 Nov 2008 16:26:25 -0600 References: <20448425.post@talk.nabble.com> X-Mailer: Apple Mail (2.929.2) X-Virus-Checked: Checked by ClamAV on apache.org Rob, Maybe, you'll need to be "headless" -Djava.awt.headless=true Yegor has been through this pain. I suggest you try the following experiment. 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. Regards, Dave 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