I have to create an XSSF sheet with multiple copies of the same 2 images over 10k times. Currently I call the following block in a loop to set the image into its various places using ClientAnchor.
ClientAnchor anchor = helper.createClientAnchor(); //helper is instance of CreationHelper
anchor.setCol1(colNumber);
anchor.setRow1(rowNumber);
anchor.setAnchorType(ClientAnchor.MOVE_DONT_RESIZE);
Picture p = drawing.createPicture(anchor, imageIndex);
p.resize();
This is making the application very slow because of the internal calls to ImageUtil's readImage function to simply get the dimension it looks like. I already have the dimensions of the image and the image byte data before this loop even runs as I read that from a file directly. Is there another way to do this?
Reference #1:
Image retrieval code:
FileInputStream imageStream = new FileInputStream("image.png");
Byte[] image = IOUtils.toByteArray(imageStream);
imageStream.close();
imageIndex = output.addPicture(image, Workbook.PICTURE_TYPE_PNG);
Reference #2: Here is a snapshot from JVM Monitor showing the internal calls of resize() and the time taken for reference.
Any thing I'm missing out on? Is there a better way to achieve this?