Update: It seems that this question boils down to that some images are correctly decoded, while some don't. If I convert the non-working JPEG
s to png
s, they work. None of my images taken directly as JPEG
s from either a Nikon D5000
, a Panasonic Lumix
or a Sony Experia
phone can be decoded.
I am using Picasso
to fill a ListView
in my Android
app. I am, however, running into the error --- decoder->decode returned false
for the images I am to use, but it works fine for other pictures I run across around the web. Therefore, I believe it has something to do with the images, but I am not really sure. The error arises in the Skia
library which is used by Picasso
(as far as I know).
For example, this image works fine, while this does not, and it is the latter I need to work. All other pictures I need to use are taken with the same camera and edited by Gimp
in the same way, resulting in images like the first one, but none of them work. Hence, I suspect it has something to do with the images themselves rather than the decoder.
A few questions that pops up:
- Is it possible that the metadata can do something in this process? The metadata are similar in all the pictures.
- Could it be something with the encoded images that makes the encoder go crazy? If so, what could it be and how can I investigate it? End of file missing or anything?
- Is it possible to enable more debugging and output from
Picasso
orSkia
? Stack traces, for example? - Will non-UTF8 characters mess things up, or is this handled correctly? The example image does not have UTF8 characters in it, but some of the images may have.
What I have tried:
- I tried opening a non-working image in
Inkscape
and exporting it as apng
file instead. Now, the image actually works, so there seems to be something with theJPEG
encoding. - Another try was to open the image in
Gimp
and exporting toJPEG
again, but that did not help. - I also tried opening the image in
Shotwell
and re-exporting toJPEG
, both with and without the metadata, but none of these images work. Exporting topng
works as with exporting topng
fromInkscape
. - All the non-working images are taken with a
Nikon D5000
camera, so I tried taking a few images with aSony Experia
phone and aPanasonic Lumix
camera. Non of theJPEG
s work directly, but if converted toPNG
they are all decoded. - I tried setting up a
Picasso.Builder
object as shown here, to get a stack trace. I have pasted the stack trace below. It might seem that it actually is theAndroid.BitmapFactory.decodeStream()
that fails, as the stack trace points tocom.squareup.picasso.BitmapHunter.decodeStream()
, which utilizesAndroid.BitmapFactory.decodeStream()
. So maybe the error has nothing to do withSkia
after all. - I also used
Imagemagick
'sidentify -verbose
on the working and the non-working images and compared the outputs. I was unable to find any differences that stood out, so it did not bring me any further.
Example Logcat output:
D/Picasso(528): Main created [R0] Request{http://www.miasmat.no/wp-content/uploads/2015/05/OvnsbaktKveite9.jpg}
D/Picasso(528): Dispatcher enqueued [R0]+7ms
D/Picasso(528): Main created [R1] Request{http://www.miasmat.no/wp-content/uploads/2015/05/OvnsbaktKveite9.jpg}
D/Picasso(528): Hunter joined [R1]+1ms to [R0]+10ms, [R1]+1ms
D/Picasso(528): Main created [R2] Request{http://www.miasmat.no/wp-content/uploads/2015/05/OvnsbaktKveite9.jpg}
D/Picasso(528): Hunter joined [R2]+1ms to [R0]+14ms, [R1]+5ms, [R2]+2ms
D/Picasso(528): Hunter executing [R0]+21ms, [R1]+12ms, [R2]+9ms
D/skia(528): --- decoder->decode returned false
D/Picasso(528): Dispatcher retrying [R0]+1456ms, [R1]+1447ms, [R2]+1444ms
D/Picasso(528): Hunter executing [R0]+1458ms, [R1]+1448ms, [R2]+1445ms
D/skia(528): --- decoder->decode returned false
D/Picasso(528): Dispatcher retrying [R0]+2867ms, [R1]+2857ms, [R2]+2854ms
D/Picasso(528): Hunter executing [R0]+2868ms, [R1]+2859ms, [R2]+2855ms
D/skia(528): --- decoder->decode returned false
D/Picasso(528): Dispatcher batched [R0]+3406ms, [R1]+3397ms, [R2]+3394ms for error
D/dalvikvm(249): GC_EXPLICIT freed 119 objects / 5288 bytes in 28ms
I/TAGZ(528): Error! url = http://www.miasmat.no/wp-content/uploads/2015/05/OvnsbaktKveite9.jpg
D/Picasso(528): Main errored [R0]+3607ms
I/TAGZ(528): Error! url = http://www.miasmat.no/wp-content/uploads/2015/05/OvnsbaktKveite9.jpg
D/Picasso(528): Main errored [R1]+3598ms
I/TAGZ(528): Error! url = http://www.miasmat.no/wp-content/uploads/2015/05/OvnsbaktKveite9.jpg
D/Picasso(528): Main errored [R2]+3596ms
D/Picasso(528): Dispatcher delivered [R0]+3610ms, [R1]+3601ms, [R2]+3598ms
Stack trace from Picasso
, pointing to this file.
W/System.err(1467): java.io.IOException: Failed to decode stream.
W/System.err(1467): at com.squareup.picasso.BitmapHunter.decodeStream(BitmapHunter.java:145)
W/System.err(1467): at com.squareup.picasso.BitmapHunter.hunt(BitmapHunter.java:217)
W/System.err(1467): at com.squareup.picasso.BitmapHunter.run(BitmapHunter.java:159)
W/System.err(1467): at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
W/System.err(1467): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
W/System.err(1467): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
W/System.err(1467): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
W/System.err(1467): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
W/System.err(1467): at java.lang.Thread.run(Thread.java:1096)
W/System.err(1467): at com.squareup.picasso.Utils$PicassoThread.run(Utils.java:411)
getView
method in my BaseAdapter
for the ListView
:
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
final View view;
Recipe recipe = this.getItem(position);
if (convertView != null){
view = convertView;
view.setTag(recipe.getId());
}
else{
view = myActivity.getLayoutInflater().inflate(R.layout.recipe_item, parent, false);
view.setTag(recipe.getId());
}
ImageView imageView = (ImageView) view.findViewById(R.id.filtered_recipes_list_image_view);
// final String foo = "https://cms-assets.tutsplus.com/uploads/users/21/posts/19431/featured_image/CodeFeature.jpg";
final String foo = "http://www.miasmat.no/wp-content/uploads/2015/05/OvnsbaktKveite9.jpg";
Picasso.with(myActivity).setIndicatorsEnabled(true);
Picasso.with(myActivity).setLoggingEnabled(true);
Picasso.with(myActivity).load(foo).into(imageView, new Callback() {
@Override
public void onSuccess() {
Log.i("TAGZ", "Success! url = " + foo);
}
@Override
public void onError() {
Log.i("TAGZ", "Error! url = " + foo);
}
});
return view;
}
Reason for that error is: You are trying to set an image of size which is more than your image view layout size.
I found a simple solution for that! If you are using picasso library for image loading..then, resize your image to fir your image view layout.
i.e, I have done like this: