You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Geoff Groskreutz <gr...@versifit.com> on 2008/01/07 18:19:03 UTC

RE: [HSSF announce] Resizing images is implemented

Yegor,

I have tested this resize functionality with the POI V3.0.2 beta 1 release,
and found that it works fine, until you change the width of any column or
the height of any row that the image will be anchored to.  Even if I call
the resize method after the column widths and row heights have been set, the
function does not seem to take into account these size changes in the
underlying columns and rows before it determines what rows and columns to
anchor it to. (I believe I am correct in assuming that the XLS format does
not allow absolute positioning and sizing of images, but instead everything
must be anchored to a cell(s)...what a pain, but anyway...)

However, since I need to change the size of columns and rows, this resize
method (I also tried the getPreferredSize method, which I am guessing is
called by the resize method) will not work, so instead I just hacked a
routine together, after I perform all necessary column and row sizing it
then finds the correct end cell to anchor the image to and then determines
the end point inside this last cell(I assume this is some percentage of the
available cell width with 1023 as max value). It also looks to me that this
is the same type of routine that you used in the resize functionality, but
it seems to only use the default row and column sizes and not their current
values.

Currently, for the "hacked" routine I have in-place for determining the
correct anchor positions, I need to know the image's actual width and height
in pixels, and I perform the proper conversions as necessary, however, the
conversion to calculate the actual width of the image for use in the column
width assignment was not intuitive (I basically had to use trial and error
to get the right conversion multiplier), since I can't quite determine what
unit of measurement is being used when setting the width of a column.

So, I guess if you wouldn't mind looking into this, it would be great.

Also, it would be great, if available, to expose (for read only) the actual
height and width (in pixels, twips, or both) of the image being loaded and
created, preferably in the HSSFPicture object itself.

Thanks,

Geoff Groskreutz
-----Original Message-----
From: Yegor Kozlov [mailto:yegor@dinom.ru] 
Sent: Monday, October 01, 2007 1:34 PM
To: POI Users List
Subject: [HSSF announce] Resizing images is implemented

Hi All,

The functionality to resize HSSF images to the actual width and height was
requested many times. 
Finally it is implemented. HSSFPicture.resize() is a handy method to reset a
picture to its original dimensions.

Usage:

    HSSFPatriarch patriarch = sheet.createDrawingPatriarch();

    HSSFPicture picture = patriarch.createPicture(new HSSFClientAnchor(),
loadPicture( "src/resources/logos/logoKarmokar4.png", wb ));
    picture.resize();

or

    HSSFPatriarch patriarch = sheet.createDrawingPatriarch();

    HSSFPicture picture = patriarch.createPicture(new HSSFClientAnchor(),
loadPicture( "src/resources/logos/logoKarmokar4.png", wb ));
    HSSFClientAnchor prefferedSize = picture.getPrefferedSize();
    picture.setAnchor(prefferedSize);

 
Note: HSSFPicture.resize() works only for PNG and JPEG. Other formats are
not yet supported.


Regards,
Yegor Kozlov



---------------------------------------------------------------------
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