Android Picasso Image does not load

萝らか妹 提交于 2019-12-12 08:29:37

问题


There are two situations I load images, first, just directly from the internet, and second, load images that are downloaded in the device. And whenever I load, 8~9 out of 10 images are shown, and 1-2 missing. I see that decode returned false, and google'd as hard as I can, but couldn't come up.

  1. WAIT_FOR_CONCURRENT_GC blocked 22ms
  2. WAIT_FOR_CONCURRENT_GC blocked 20ms
  3. GC_FOR_ALLOC freed 718K, 31% free 9948K/14256K, paused 49ms, total 51ms
  4. D/skia: --- decoder->decode returned falseGC_CONCURRENT freed 1370K, 30% free 10081K/14256K, paused 3ms+2ms, total 33ms
  5. GC_FOR_ALLOC freed 916K, 30% free 10029K/14256K, paused 66ms, total 67ms

Here's code I use to load through Picasso:

        Picasso.with(activity)
            .load(path)
            .placeholder(R.drawable.thumbnail_placeholder)
            .resize(width,height)
            .into(imageView);

Any ideas how to solve this issue? I am calling fit()/resize() every time I get the images to load on the screen. Help much appreciated, thanks in advance!

FYI, I test on both machines, emulator and the real device, Samsung Galaxy Tab 3, and works without any problems on emulator, but problems occur on real device.

UPDATE:

It was causing by image's color space, where images that weren't showing up were the ones that were in YMCK color space.


回答1:


You can turn on Picasso logs using Picasso.with(Context).setLoggingEnabled(true). You will probably see an error message with a reason there.

It's also worth logging the URL you are using and trying it a browser, just in case.




回答2:


check Internet permission in manifaest

<uses-permission android:name="android.permission.INTERNET"/>



回答3:


In Picasso you shoud pass url in .load() method to load picture from internet and object of File type to load picture from device storage.

So if the picture is stored on device load it like this:

        Picasso.with(activity)
                .load(new File(path))
                .placeholder(R.drawable.thumbnail_placeholder)
                .resize(width,height)
                .into(imageView);

And use this code to load picture from internet:

        Picasso.with(activity)
                .load(path)
                .placeholder(R.drawable.thumbnail_placeholder)
                .resize(width,height)
                .into(imageView);



回答4:


Don't know its relevant to this issue or not but my problem is solved by using Glide instead of Picasso.




回答5:


If anything not works, it is because of the some problem with the servers that are hosting images, their url does not directly take you to the image, but in backend something else is working, it may open in chrome or other browser, but not for sure in picasso it will load, so you may try this code :

final OkHttpClient client = new OkHttpClient.Builder()
        .protocols(Collections.singletonList(Protocol.HTTP_1_1))
        .build();

final Picasso picasso = new Picasso.Builder(this)
        .downloader(new OkHttp3Downloader(client))
        .build();

Picasso.setSingletonInstance(picasso);

where the OkHttp3Downloader instance is supplied by this library. https://github.com/JakeWharton/picasso2-okhttp3-downloader




回答6:


Take a look of Picasso: out of memory

Check that you use fixed size in your ImageView, refer to more info to @Samuil Yanovski answer

Hope this helps!!




回答7:


I was facing the same error, I resized the same image and uploaded it to firebase then load its URL using picasso and this time it worked totally fine; image was loaded successfully.

Same image was not showing nor there were any picasso logs before it was resized.

It took me almost two days to realise that real issue was with image size. I resized my image to 500x500 and everything worked fine.

NOTE: In my case I was capturing image from device's camera then uploading it to firestore and then loading image using picasso. So to fix the issue I started to resize image in onActivityResult() method then save resized image to local storage and uploaded it to firestore.




回答8:


Make sure your imageUrl contains https instead of http If your imageUrl contain http then creat network_Security_config file under res folder xml folder and mention the URL E.g

    <<network-security-config>
            <domain-config cleartextTrafficPermitted="true">
                <domain includeSubdomains="true">www.your_domain.com</domain>
            </domain-config>
    </network-security-config>


来源:https://stackoverflow.com/questions/36045522/android-picasso-image-does-not-load

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!