Created attachment 37088 [details] 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.
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
Thank you for bringing this up ... and your continued support in StackOverflow. Patched via r1875266