You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2020/03/10 12:52:42 UTC

[Bug 64213] New: Picture.resize(double scale) scales width wrong for small pictures and when dx1 is set.

https://bz.apache.org/bugzilla/show_bug.cgi?id=64213

            Bug ID: 64213
           Summary: Picture.resize(double scale) scales width wrong for
                    small pictures and when dx1 is set.
           Product: POI
           Version: unspecified
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: SS Common
          Assignee: dev@poi.apache.org
          Reporter: axel.richter.privat@web.de
  Target Milestone: ---

Created attachment 37088
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=37088&action=edit
Images used

For small pictures and if there is dx1 set in anchor, Picture.resize(double
scale) scales width wrong.

Example to reproduce:

import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;

import org.apache.poi.util.IOUtils;
import org.apache.poi.util.Units;

import java.io.InputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;

class PictureResizeBug {

 public static void main(String[] args) throws Exception {

  //Workbook wb = new HSSFWorkbook(); String resultName =
"PictureResizeBug.xls";
  Workbook wb = new XSSFWorkbook(); String resultName =
"PictureResizeBug.xlsx";
  Sheet sheet = wb.createSheet("Sheet1");

  String picturePath = "./candle200x200.png";
  //String picturePath = "./candle400x400.png";
  int pictureType = Workbook.PICTURE_TYPE_PNG;

  int col1 = 2;
  int dx1 = 100;
  int row1 = 2;
  float scale = 0.5f;

  sheet.setColumnWidth(col1, 50 * 256);

  //load the picture
  InputStream inputStream = new FileInputStream(picturePath);
  byte[] bytes = IOUtils.toByteArray(inputStream);
  int pictureIdx = wb.addPicture(bytes, pictureType);
  inputStream.close();

  //create an anchor with upper left cell column/startRow, only one cell anchor
since bottom right depends on resizing
  CreationHelper helper = wb.getCreationHelper();
  ClientAnchor anchor = helper.createClientAnchor();
  anchor.setCol1(col1);
  if (wb instanceof XSSFWorkbook) {
   anchor.setDx1(dx1 * Units.EMU_PER_PIXEL);
  } else if (wb instanceof HSSFWorkbook) {
   anchor.setDx1(dx1);
  }
  anchor.setRow1(row1);

  //create a picture anchored to Col1 and Row1
  Drawing drawing = sheet.createDrawingPatriarch();
  Picture pict = drawing.createPicture(anchor, pictureIdx);

  //resize the picture to it's native size
  pict.resize();

  //resize the picture scaled proportional
  pict.resize(scale);

  FileOutputStream fileOut = new FileOutputStream(resultName);
  wb.write(fileOut);
  fileOut.close();
  wb.close();

 }
}


Here for candle200x200.png, a 200px + 200px PNG image, the result of this code
is a picture in Excel which is correctla scaled 0.25 in heigth but 0.90 in
width for HSSF and 1.37 in width for XSSF. If candle400x400.png is used, the
scaliing works properly in height and width.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 64213] Picture.resize(double scale) scales width wrong for small pictures and when dx1 is set.

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=64213

Axel Richter <ax...@web.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|unspecified                 |4.1.2-FINAL

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 64213] Picture.resize(double scale) scales width wrong for small pictures and when dx1 is set.

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=64213

ivannovak90@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ivannovak90@gmail.com

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 64213] Picture.resize(double scale) scales width wrong for small pictures and when dx1 is set.

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=64213

--- Comment #1 from Andreas Beeker <ki...@apache.org> ---
I haven't yet checked the problem, but I think the following stackoverflow
entry corresponds to the issue (just as a reference ...):

https://stackoverflow.com/questions/60600112/apache-poi-keep-original-picture-scale-while-fitting-within-a-merged-region

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 64213] Picture.resize(double scale) scales width wrong for small pictures and when dx1 is set.

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=64213

Andreas Beeker <ki...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED

--- Comment #2 from Andreas Beeker <ki...@apache.org> ---
Thank you for bringing this up ... and your continued support in StackOverflow.

Patched via r1875266

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org