Picasso: Images at certain URLs do not load (was: Images that need to be resized up do not display at all)

Created on 4 Sep 2013  ·  35Comments  ·  Source: square/picasso

I have two ImageViews; one is 218x192 and the other is 278x192. If I load the same 250x250 image into both of these views with resize([ImageView size]) and centerCrop(), the image is displayed in the first ImageView (which resizes the image down to 218) but not in the second ImageView (which would resize the image up to 278). Only the placeholder is displayed in the second ImageView. I believe this is a regression in 2.0.0 and the upsizing was working previously.

Most helpful comment

Does your URL have white spaces? Some of mine have, and my workaround is
url = url.replaceAll(" ","%20");

All 35 comments

Sample app always helps in this case. I will investigate today.

I edited the sample app to simulate exactly the scenario you described. Both imageviews correctly loaded the image and displayed it. The same source image was re-used but the resize was different. See screenshot.

Can you provide a sample app that reproduces the problem? It would really help me see if there is a problem.

    ImageView imageView1 = (ImageView) findViewById(R.id.image1);
    ImageView imageView2 = (ImageView) findViewById(R.id.image2);

    Picasso.with(this).setDebugging(true);

    Picasso.with(this).load(Data.URLS[0]).placeholder(R.drawable.placeholder).resize(218, 192).centerCrop().into(imageView1);
    Picasso.with(this).load(Data.URLS[0]).placeholder(R.drawable.placeholder).resize(278, 192).centerCrop().into(imageView2);

device-2013-09-04-074142

I even tried it on a 250x250 image from a drawable resource and it still worked.

Sure, I'll dive into it and try to find the difference. Did you also have success when the images were loaded from the remote source? It looks like they were loaded from local cache in the screenshot.

First time it was remote and the indicator was red. I just relaunched the app afterwards and they were loaded from disk. That's when I took the screenshot.

It doesn't appear that this is related to resizing in Picasso, but instead possibly something to do with reading the server response. I believe I have found steps that will allow you to reproduce the problem. Try loading this image into an ImageView. I only see the placeholder.

Towards the end of the URL you can see that the image size is specified with "w250-h250". If I decrease either of those numbers, for example to "w249-h250", then the image does appear, though it has a transparent background and you can see the placeholder behind it.

If I swap in Picasso 1.1.1 instead of 2.0.0, then both problems disappear. I can load the "w250-h250" version and the placeholder is no longer displayed once the image is loaded.

Looking into this now. thanks for the link,

Confirmed. This is a bug in MarkableInputStream and reset. Url is "https://lh4.googleusercontent.com/-Hq9oxoY5GfM/UbDO6l1dxtI/AAAAAAAAAA4/kRjknWKvQXQ/s1600-w250-h250/DaysInn.png"

The reason you don't see in Picasso 1.1.1 is because MarkableInputStream does not exist :)

Fixed for 2.0.1.

I'm getting the same/similar error with 2.0.1. I added this url to the Data class and loaded the samples and it just shows the error picture (white background, creepy guy).

https://s3.amazonaws.com/images.couchsurfing.us/NWNGC2A/17529011_m_9dd30543136eadda012c5fbdcc47c68f.jpg

Stacktrace:

java.io.IOException: Cannot reset
        at com.squareup.picasso.MarkableInputStream.reset(MarkableInputStream.java:94)
        at com.squareup.picasso.NetworkBitmapHunter.decodeStream(NetworkBitmapHunter.java:91)
        at com.squareup.picasso.NetworkBitmapHunter.decode(NetworkBitmapHunter.java:60)
        at com.squareup.picasso.BitmapHunter.hunt(BitmapHunter.java:111)
        at com.squareup.picasso.BitmapHunter.run(BitmapHunter.java:82)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390)
        at java.util.concurrent.FutureTask.run(FutureTask.java:234)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
        at java.lang.Thread.run(Thread.java:841)
        at com.squareup.picasso.Utils$PicassoThread.run(Utils.java:218)

If I comment out the resize call in the RequestCreator, it works fine and the image displays.

Can you bump NetworkBitmapHunter stream buffer to 8192 and see it does it ? This is an increasing problem we have that needs a better solution.

Hmm commenting out the resize call does it, that's interesting.

I tried the increased buffer and it didn't work. I'll try investigating further.

Thanks, I will spend sometime on it today later.

I'm also experiencing these errors. Can confirm it only errors if a resize is involved. Seeing markStream.offset = 4116 which is causing the IOException in markStream.reset()

Let me know if more data points would help.

In my case, the markStream.offset = 11201.

I looked at the source for BitmapFactory and inside, they have a DECODE_BUFFER_SIZE = 16 * 1024. They also do a is.mark(1024) in decodeStream, but since the offset is > 1024, the stream isn't reset back to the start position and 4096 or 8192 aren't large enough to reset the stream in the MarkableInputStream (I think?).

https://github.com/android/platform_frameworks_base/blob/dbc51de44fe4f9a7f81528204250de32ec405d39/graphics/java/android/graphics/BitmapFactory.java

I set the limit to 16 * 1024 and it worked.

It's funny that the comment on the BitmapFactory's mark(1024) in decodeStream says "FIXME: need to find out from the codecs what this value should be."

The URL we referenced previously now loads, but here's another one that isn't loading. (Contrary to the extension in the URL, it's actually a PNG.)

Thanks everyone for their reports. We did not think the 4096 in 2.0.1 will fix it permanently. It seems we have a bigger issue one that needs to be handled for a 2.0.2 release.

Please be patient or provide a pull request if you can fix it before us!

Re-opening this for next release.

Try v2.0.2

That fixes my issue, thanks!

Hello. It looks like the bug still happens in v2.2.0.

Does your URL have white spaces? Some of mine have, and my workaround is
url = url.replaceAll(" ","%20");

No, they only have numbers, lowercase letters, and underscores.

On Fri, May 16, 2014 at 2:57 PM, Christian Göllner <[email protected]

wrote:

Does your URL have white spaces? Some of mine have, and my workaround is
url = url.replaceAll(" ","%20");


Reply to this email directly or view it on GitHubhttps://github.com/square/picasso/issues/234#issuecomment-43327804
.

So is there a way I can reopen the bug for the next version?

Show us your URL

I was testing on images in a local server. I temporarily uploaded one that did not work so you can test it, here: http://neptilo.com/cover_1_original.jpg

The URL is not the problem, but rather the content of the image imo.

Edit: some others that don't work: http://neptilo.com/cover_2_original.jpg, http://neptilo.com/cover_3_original.jpg, http://neptilo.com/cover_4_original.jpg

Are you able to reproduce the bug?

No one answered, so I'll delete the test images.

Here is another one havent problem.

http://caraka-online.com/wp-content/uploads/2014/09/IMG_6574.jpg

Picasso picasso = Picasso.with(this);
picasso.setLoggingEnabled(BuildConfig.DEBUG);
picasso.setIndicatorsEnabled(BuildConfig.DEBUG);

the log i am getting is just

09-19 01:34:48.124  21052-21068/com.caraka.carakanews 
D/Picasso﹕ Dispatcher  batched      [R15]+1534ms for error (will replay)

This is how i load the image in a ListAdapter

mPicasso.load(newsItem.getAttachmentUrl())
    .resizeDimen(R.dimen.thumbnail_size, R.dimen.thumbnail_size)
    .centerInside()
    .into(holder.imageView);

The R.dimen.thumbnail_size was 70dp

and i am using

compile 'com.squareup.picasso:picasso:2.3.4'

Here is another URL that cannot be loaded

http://www.dbs.com.sg/iwov-resources/images/offers/cards/TRA00001-620x216.jpg

I am using version 2.4.0

I have few images that cant be loaded as well. I am using version 2.4.0 as well. Did any of you found an work around for this issue?

The only workaround I used at the time was avoiding using some filters like fitting, resizing or centering, but of course you don't get the same result visually.

@Neptilo Thanks for the quick response :)

I've been faced with the similar problem.
loading image is:

https://farmer.arlafoods.de/nextshopcms/cmsimage.asp?id=5684&fkt=3

I thought that the problem related to server (.asp) response and url don't have a format like .png or
.jpg but in other cases, I able to load some links like http://goo.gl/gEgYUd.
Additionally, the strange thing that I able to load this link in a browser and Postman.

Diving to the logs from Picasso I've seen that this particular url has some error.
As I understand the Dispatcher added some delay for loading image and again and again.

Dispatcher batched [R60]+431ms for completion
Dispatcher batched [R60]+359ms for completion
.
.
and as a result
Dispatcher batched [R60]+2216ms for error

I've put an OkHttpClient with timeout delay in 10 sec but it doesn't help.
Is anybody has some ideas how to hold this case?

_Update_

I found some facts that the request makes based on device resolution _resize(xxx,xxx)_ .

Main created [R58] Request{https://farmer.arlafoods.de/nextshopcms/cmsimage.asp?id=5684&fkt=3 resize(720,1134) centerInside}

And for resolution 720,1134 it works. But for Nexus 6p with resolution (1440,2308) the particular image, not loaded.

_Update_ 2.0
Doesen't work on any devices from 25 api.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kosttek picture kosttek  ·  24Comments

pfives picture pfives  ·  17Comments

neodroidpune picture neodroidpune  ·  21Comments

riclage picture riclage  ·  23Comments

Bersh picture Bersh  ·  18Comments