mirror of https://github.com/apache/poi.git
fixed bug #45829: HSSFPicture.getImageDimension() fails when DPI of image is zero
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@696622 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
159d3c265e
commit
cf2c1b3c7e
|
@ -235,6 +235,12 @@ public class HSSFPicture
|
|||
BufferedImage img = r.read(0);
|
||||
|
||||
int[] dpi = getResolution(r);
|
||||
|
||||
//if DPI is zero then assume standard 96 DPI
|
||||
//since cannot divide by zero
|
||||
if (dpi[0] == 0) dpi[0] = 96;
|
||||
if (dpi[1] == 0) dpi[1] = 96;
|
||||
|
||||
size.width = img.getWidth()*96/dpi[0];
|
||||
size.height = img.getHeight()*96/dpi[1];
|
||||
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 259 B |
|
@ -47,4 +47,18 @@ public final class TestHSSFPicture extends TestCase{
|
|||
assertEquals(848, anchor1.getDx2());
|
||||
assertEquals(240, anchor1.getDy2());
|
||||
}
|
||||
|
||||
/**
|
||||
* Bug # 45829 reported ArithmeticException (/ by zero) when resizing png with zero DPI.
|
||||
*/
|
||||
public void test45829() {
|
||||
HSSFWorkbook wb = new HSSFWorkbook();
|
||||
HSSFSheet sh1 = wb.createSheet();
|
||||
HSSFPatriarch p1 = sh1.createDrawingPatriarch();
|
||||
|
||||
byte[] pictureData = HSSFTestDataSamples.getTestDataFileContent("45829.png");
|
||||
int idx1 = wb.addPicture( pictureData, HSSFWorkbook.PICTURE_TYPE_PNG );
|
||||
HSSFPicture pic = p1.createPicture(new HSSFClientAnchor(), idx1);
|
||||
pic.resize();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue