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

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Bugzilla from bugzilla@apache.org
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: [hidden email]
          Reporter: [hidden email]
  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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

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

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

[hidden email] changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |[hidden email]

--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

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

Bugzilla from bugzilla@apache.org
In reply to this post by Bugzilla from bugzilla@apache.org
https://bz.apache.org/bugzilla/show_bug.cgi?id=64213

Axel Richter <[hidden email]> 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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

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

Bugzilla from bugzilla@apache.org
In reply to this post by Bugzilla from bugzilla@apache.org
https://bz.apache.org/bugzilla/show_bug.cgi?id=64213

--- Comment #1 from Andreas Beeker <[hidden email]> ---
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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

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

Bugzilla from bugzilla@apache.org
In reply to this post by Bugzilla from bugzilla@apache.org
https://bz.apache.org/bugzilla/show_bug.cgi?id=64213

Andreas Beeker <[hidden email]> changed:

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

--- Comment #2 from Andreas Beeker <[hidden email]> ---
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: [hidden email]
For additional commands, e-mail: [hidden email]