Bug 59290

Summary: EMF images embedded in excel spreadsheet are returned much smaller the actual file image
Product: POI Reporter: Barry <jbjhschiff>
Component: XSSFAssignee: POI Developers List <dev>
Status: RESOLVED WORKSFORME    
Severity: normal    
Priority: P2    
Version: 3.14-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: All   
Attachments: example file with emf picture

Description Barry 2016-04-08 18:55:36 UTC
No matter how I try to get the picture data (byte array) it is always MUCH smaller then what is actual image embedded in the excel file for EMF images. I know this is fact because I took an Excel file (say X.xlsx)  made a copy of this file and renamed it it to X.zip.  Open the archive and went to the \xl\media\ folder and the embedded original image files are listed in their full original size and resolutions.  For example one emf image had a size of 804,036 bytes.  If I call the getData on the picture programmatically using the below code the byteArray is a much smaller, for that same image for example it was 129KB instead of 804KB.  The image is a valid image just much lower quality to the point that I really can't use it.  Is there some hidden scaling down of EMI images? If so can I control this?  


InputStream inp = new FileInputStream(xlsxFilename);
Workbook wb = WorkbookFactory.create(inp);
XSSFSheet sheet = (XSSFSheet) wb.getSheetAt(0);

for (XSSFShape shape : sheet.getDrawingPatriarch().getShapes()) {
       XSSFPicture picture = (XSSFPicture) shape;
       byte[] imageBytes = picture.getPictureData().getData();
.....
       }
Comment 1 Barry 2016-04-08 21:16:42 UTC
By the way it was using Office 2016
Comment 2 Andreas Beeker 2016-04-10 21:33:47 UTC
Created attachment 33745 [details]
example file with emf picture
Comment 3 Andreas Beeker 2016-04-10 21:36:49 UTC
It's always a pity when a bug entry is not accompanied by an example file.

So I've made up one myself (via Office 20169 ... and it works ... with the following code


@Test
public void emftest() throws IOException {
    InputStream inp = new FileInputStream("emftest.xlsx");
    XSSFWorkbook wb = new XSSFWorkbook(inp);
    XSSFSheet sheet = wb.getSheetAt(0);
    for (XSSFShape shape : sheet.getDrawingPatriarch().getShapes()) {
        XSSFPicture picture = (XSSFPicture) shape;
        byte[] imageBytes = picture.getPictureData().getData();
        FileOutputStream fos = new FileOutputStream("bla.emf");
        fos.write(imageBytes);
        fos.close();
    }
    wb.close();
    inp.close();
}
Comment 4 Barry 2016-04-10 23:23:11 UTC
I did not say it did not work. i said the returned file is not the full size/resolution as the original and the quality is often un-usable. Are you saying the this does not happen with you>
Comment 5 Andreas Beeker 2016-04-10 23:36:21 UTC
yes ... the files extracted by POI vs. opening the .xlsx as .zip have the same size. If unsure, add another example .xlsx!