I'm trying to change resize the inserted image in Excel sheet using NPOI. Here is an example of code:
IWorkbook workbook;
if (useOldExcelFormat)
workbook = new HSSFWorkbook();
else
workbook = new XSSFWorkbook();
ISheet sheet = workbook.CreateSheet("My sheet");
IDrawing patriarch = sheet.CreateDrawingPatriarch();
int picId = workbook.AddPicture(imageBytes, PictureType.JPEG);
IClientAnchor anchor = patriarch.CreateAnchor(0, 0, 0, 0, columnIndex, rowIndex, columnIndex + 1, rowIndex + 1);
IPicture picture = patriarch.CreatePicture(anchor, picId);
picture.Resize(0.5);
But this code isn't working properly. The image is inserted, but with wrong proportions: image is significantly stretched vertically and/or horizontally and also the image is getting scaled differently depending on workbook type I'm creating (HSSF or XSSF).
I've found information that Resizes method work properly only with default font (Calibri 11 for XSSF). But even with default font resizing still works wrong.
Are there any ways to resize image properly with NPOI?
I've found this: AddDimensionalImage. It shows full example how to insert image into sheet with specific dimensions. Helped me a lot. May not work properly for NPOI when row has cells with autowrapped text, so it's better to calculate actual row height first.