Bug 56928

Summary: Picture resizing does not work with WMF files
Product: POI Reporter: Martin Studer <martin.studer>
Component: XSSFAssignee: POI Developers List <dev>
Status: NEW ---    
Severity: normal    
Priority: P2    
Version: 3.11-dev   
Target Milestone: ---   
Hardware: PC   
OS: Linux   

Description Martin Studer 2014-09-08 13:51:59 UTC
Picture resizing does not seem to work with windows meta files (WMF). The following is a reproducible example:

Workbook workbook = new XSSFWorkbook(); // could also use HSSF
Sheet sheet = workbook.createSheet("test");
Name name = workbook.createName();
AreaReference aref = new AreaReference(name.getRefersToFormula());
CellReference topLeft = aref.getFirstCell();
CellReference bottomRight = aref.getLastCell();

int imageType = Workbook.PICTURE_TYPE_WMF;

InputStream is = new FileInputStream(new File("/home/mstuder/test.wmf"));
byte[] bytes = IOUtils.toByteArray(is);
int imageIndex = workbook.addPicture(bytes, imageType);

Drawing drawing = sheet.createDrawingPatriarch();
CreationHelper helper = workbook.getCreationHelper();
ClientAnchor anchor = helper.createClientAnchor();
anchor.setRow2(bottomRight.getRow() + 1);
anchor.setCol2(bottomRight.getCol() + 1);

Picture picture = drawing.createPicture(anchor, imageIndex);
workbook.write(new FileOutputStream(new File("/home/mstuder/test.xlsx")));

When commenting out picture.resize() the picture is added properly with the size of the named range "test". Including picture.resize(), no image is added at all. Picture resizing works fine with other image types such as jpeg and png.