Closed VenomVendor closed 11 years ago
I have the same problem with local images. For now ,i changed the code like this (in BaseImageDecoder), perhaps could help to someone.
In defineImageSizeAndRotation function , check if mark is supported like this:
if(imageStream.markSupported())
imageStream.reset();
else
imageStream.close();
And in decode function i did:
Options decodingOptions = prepareDecodingOptions(imageInfo.imageSize, decodingInfo);
if(!imageStream.markSupported())
imageStream = getImageStream(decodingInfo);
Bitmap decodedBitmap = decodeStream(imageStream, decodingOptions);
Have the same problem with images from web. version 1.8.7 snapshot
@Henry84 would you please explain your fix or make it as pull request
I have the same problem and noticed that it is almost exclusive to .JPG photos. I have a set of PNG files and none of them seems to be affected by it, even if the files are slightly larger. The method pointed out by @Henry84 also did't make a difference to me.
I have the same problem with some jpg images on 1.8.7 version. Can't figure out the reason. Please, help. Solution by @Henry84 doesn't work
I've encountered the same IOException when image from the same URL was fetched multiple times simultaneously. Problem disappeared after eliminating mentioned circumstance by enabling caching. Note: this is not a fix, rather workaround for some cases. I've not investigated what the exact reason is. Mark is invalidated when more bytes than (previously set) read limit have been read from given InputStream.
I also had to close the stream if I get the exception with stream.reset. Worked for me.
@siyamed would you please explain your fix?
@poel I was already using our own ImageDecoder class which is a simplified version of the one included in the library.
I had to update the following function:
protected ImageFileInfo defineImageSizeAndRotation(InputStream imageStream) throws IOException {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(imageStream, null, options);
boolean streamClosed = false;
try{
imageStream.reset();
} catch (Throwable t) {
imageStream.close();
streamClosed = true;
}
return new ImageFileInfo(new ImageSize(options.outWidth, options.outHeight), streamClosed);
}
Then in the main decode function, I made the following change:
public Bitmap decode(ImageDecodingInfo decodingInfo) throws IOException {
InputStream imageStream = getImageStream(decodingInfo);
ImageFileInfo imageInfo = defineImageSizeAndRotation(imageStream);
if(imageInfo.streamClosed) {
imageStream = getImageStream(decodingInfo);
}
....
As you can see if I get an error during reset function, I mark it, close it, and in the decode function according to that flag I re-create the stream.
I am also experiencing this on 1.8.7 with the image http://i.imgur.com/F4ism2b.jpg
Funny, never happened before, but today I'm getting this error with some pictures I took with my old phone. I copied them to my new phone and they won't load. There's no problem at all with pictures taken with my current phone's camera.
Old Phone: Samsung GT-I9003L Current Phone: Samsung GT-I8190L
@siyamed made this fix useless: @nostra13 tryied to increase performance reusing InputStream -> BufferedInputStream, BUT as said in http://code.google.com/p/android/issues/detail?id=57578 article BitmapFactory.decodeStream(bis, null, options); will kill all marks on Buffer and calling reset may create IO EXCEPTIONS in thoes cases (actually as I did ) we can replace InputStream (in DECODE methode) with one of them: https://github.com/bumptech/glide/blob/fdb5f853e615ab46a4f3dea3a46bfca09c75f27a/library/src/com/bumptech/glide/resize/RecyclableBufferedInputStream.java
I'm using picasso IS with bufer size of 1024*1024 and for my HTC ONE it's very good. Hope this fix will be applied in next release of main branch =] good luck(6 hours spent to solve total)
@FedulovDeveloper Thanks.
Just cloned the last update. Work perfectly! Thanks @nostra13 and @FedulovDeveloper :-)
universal-image-loader-1.8.6.jar
1.8.6
and switch to1.8.7
the image which was downloaded twice with different names gets deleted from cache dirConfig
Options