-
Notifications
You must be signed in to change notification settings - Fork 6.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exception occurred when loading large .bmp file #283
Comments
Any chance you might be willing to attach an image that causes this? Either it's an image with a >5mb header, or we're incorrectly parsing the header for bmps. |
@sjudd I think Glide doesn't support Windows bitmaps (.bmp), that is no hardcoded type: see how the image file type is determined. I think the reason for this exception is that the decoding is passed to Android which fails here, from the stackstrace (I guess this is what you mean with >5MB header) even though they list BMP as supported without any remarks. @CuongSmile Apart from all this I highly suggest you rethink using uncompressed images of any form. I think it is really inefficient: battery, processor, bandwidth, space and did I mention battery? :) |
@sjudd Thanks for supporting. Sorry I can't attach the image that causes this (becase my boss doesn't allow it).But I can load .bmp files have large about 1-2 MB . |
I find an .bmp file at here.When i loading it , an exception same above appeared. |
@CuongSmile what version of Android are you seeing this on? Unfortunately it looks like BitmapFactory may be trying to read the entire file with inJustDecodeBounds set to true, which isn't going to be trivial to work around. |
@sjudd I run my app on Nexus 5 (Android 5.0) and Nexus 4 (Android 4.4.4) |
@sjudd would it be too hacky to read the header yourself in case of |
Looks like we will have to do something like that for now. I'll look in to it more, it may be a framework issue we can get fixed. |
@sjudd Thanks for caring my problem. I want to ask you one question. Can I create new an inputstream to image if the exception above occurred ? |
Could you re-request the image to avoid this problem in the mark has been invalidated? In theory yes you could. Multiple network requests to decode an image aren't particularly appealing though... |
Underlying cause appears to be a BitmapFactory issue, it reads the entire stream when decoding .bmps. Internal bug is b/9484121. I'll look in to a workaround. There is a generic class of error here which is a more serious bug. We shouldn't fail to decode an image just because we need to read more data than we expect to get the image header. Instead we should just use a sample size of 1 and decode the full image. Probably the right way to do this would be to open a second InputStream, but since that's both expensive and not practical given the current implementation, I'll look in to some solution where we eagerly throw an exception before the mark is invalidated. |
@sjudd ok.thanks you very much.I think i need changed some point in your library to fix this problem, Hoping you will be fix it early.:) |
Fixes bumptech#283. We use BitmapFactory.Options#inJustDecodeBounds to decode the width and height of images before decoding the full image so that we can downsample large images to avoid memory pressure. To do so, we use mark/reset on a buffered InputStream. To handle images with large headers, we set a large (currently 5mb) mark limit. However, there's always the chance that that limit is insufficient even with a well formatted image and a bug free decoder. Since downsampling is typically an optimization, if such a failure occurs we still want to decode the full image, even if we can't obtain the dimensions. By enforcing we don't read beyond our limit, we ensure that the header read fails recoverably, so that the full image can still be decoded.
I'm use glide-3.4.0.jar to load image in my app. But a exception occurred when loading large .bmp file (~20MB)
The below is my stacktrace.
The text was updated successfully, but these errors were encountered: