I have an Android app that takes photos, converts them to Bitmap using:
private Bitmap generateBitmap(byte[] data) {
Bitmap bmp = BitmapFactory.decodeByteArray(data, 0, data.length);
Matrix mat = new Matrix();
mat.postRotate(-90);
return Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(),
bmp.getHeight(), mat, true);
}
then to PNG using:
bitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream);
The outputStream
is then posted (multipart/form-data) to my web server (jboss). On the server, jax-rs and MultipartForm convert it to a data[] and send on for additional processing that begins with:
BufferedImage image = ImageIO.read(new ByteArrayInputStream(form.getImageFileData()));
The app is in production and works as expected, until now. We activated a new user last week (Samsung Galaxy Note Edge) and every single photo he uploads generates javax.imageio.IIOException: Error reading PNG image data
when I invoke ImageIO.read() where the root cause of the stack trace is:
Caused by: java.util.zip.ZipException: incorrect data check
The photos display properly in a browser but I am unable to fully process them because of this exception. I can also open them in an editor rotate them 360 degrees, re-save them and then process them just fine.
Can anyone help me understand what could cause this problem on just this one device or suggest something I can do on the server to work around it and still generate the BufferedImage
I need for further processing? Manually editing each photo is not an option.
UPDATE: As suggested, I ran pngcheck on 14 photos from this device. It returned 2 valid and 12 invalid with error: zlib: inflate error = -3 (data error)
. All 14 fail as described above using ImageIO.
An image with this problem can be seen at: https://tracweb-safecommunity.rhcloud.com/rest/monitoredProfile/106/testResult_8284.png