Bug 59290 - EMF images embedded in excel spreadsheet are returned much smaller the actual file image
Summary: EMF images embedded in excel spreadsheet are returned much smaller the actual...
Status: RESOLVED WORKSFORME
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.14-FINAL
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-04-08 18:55 UTC by Barry
Modified: 2016-04-10 23:36 UTC (History)
0 users



Attachments
example file with emf picture (13.94 KB, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
2016-04-10 21:33 UTC, Andreas Beeker
Details

Note You need to log in before you can comment on or make changes to this bug.
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!