18

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.

xosuma
  • 267
  • 1
  • 3
  • 11

18 Answers18

40

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.

MC Emperor
  • 22,334
  • 15
  • 80
  • 130
Matthew Shearer
  • 2,715
  • 3
  • 23
  • 32
28

check Internet permission in manifaest

<uses-permission android:name="android.permission.INTERNET"/>
Tarun Umath
  • 900
  • 10
  • 7
15

Try to replace "http:" at the start of your Url with "https:" (if it applies)

(on your String representation of Url).replace("http:", "https:");

Works for me.

Andrij
  • 218
  • 2
  • 8
10

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);
dzikovskyy
  • 5,027
  • 3
  • 32
  • 43
  • this post has helped me to load image from storage. thanks! – Sam Jul 02 '17 at 23:04
  • Do you know how to centercrop without specifying the width and height? Glide does it automatically but Picasso requires you to provide the values. – TheRealChx101 Aug 31 '19 at 15:31
8

You can use Picasso.with(Context).setLoggingEnabled(true) to enable debugging so as to troubleshoot the exact cause . If the log has something like Error 504 try using:

android:usesCleartextTraffic="true"

in Application tag of your manifest. It worked for me

Answered here

Vivek Thummar
  • 395
  • 4
  • 17
kamasuPaul
  • 173
  • 1
  • 9
7

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

Gentle
  • 519
  • 6
  • 12
  • Same thing here (on 7/25/19) .. Picasso wouldn't load the image, but glide does. Not sure why. – Jayce Jul 26 '19 at 00:45
4

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

1

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!!

Community
  • 1
  • 1
Gueorgui Obregon
  • 5,077
  • 3
  • 33
  • 57
1

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.

AS Mackay
  • 2,831
  • 9
  • 19
  • 25
Ahmad Sadiq
  • 153
  • 1
  • 1
  • 8
1

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>
Mayur Rathod
  • 361
  • 3
  • 13
1

Check if you have these permissions in the manifest:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET"/>
Sunny Patel
  • 194
  • 1
  • 10
1

Maybe this helps someone,

For my url I was using http://localhost:8080/api/get-image/image.jpg...

You need to set instead of localhost, the server's ip!!

1

//first store the link in string

String url =     
        "https://i.pinimg.com/originals/fc/92/13/fc9213e50a1978c845d7195e988a3322.jpg";
        Picasso.with(this).load(url).into(imageView);
Mazhar Iqbal
  • 813
  • 7
  • 7
1

Hope this solution helps someone

Create xml file name network and paste that code in that file

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true">
        <trust-anchors>
            <certificates src="system" />
        </trust-anchors>
    </base-config>
</network-security-config>

Add/Include this network.xml file and this line android:usesCleartextTraffic="true" in your Manifest like this

 <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:networkSecurityConfig="@xml/network"
        android:usesCleartextTraffic="true"

Happy coding, Stay safe

Abdul Basit Rishi
  • 2,268
  • 24
  • 30
0
 Picasso.with(activity)
            .load(path)
            .placeholder(R.drawable.thumbnail_placeholder)
            .resize(width,height)
            .into(imageView);

replace it with this below code

 Picasso.get()
            .load(path)
            .placeholder(R.drawable.thumbnail_placeholder)
            .resize(width,height)
            .into(imageView);
MEGHA DOBARIYA
  • 1,622
  • 9
  • 7
0

Use link below

Picasso.Get().Load(imageUri).Placeholder(Resource.Drawable.patient_profile_pic).Resize(100, 100).Into(imgProflle);

Xamarin or .Net

 byte[] imageBytes;


    using (var webClient = new WebClient())
    {
      imageBytes = webClient.DownloadData(imageUri);
    }

    Bitmap bitmap = BitmapFactory.DecodeByteArray(imageBytes, 0, imageBytes.Length);

    imgProflle.SetImageBitmap(bitmap);
logeshpalani31
  • 1,416
  • 12
  • 33
0

I had faced the same issue but below is the solution which is worked for me.

implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.squareup.okhttp:okhttp:2.3.0'
implementation 'com.squareup.okhttp:okhttp-urlconnection:2.3.0'

===============================================================================

private static Picasso picasso = null;
public static Picasso.Builder picassoBuilder ;


public static void loadImageInto(Context context, String url, int width, int 
 height, Target target) {
    initPicasso(context);
  picasso.load(url)
            .error(android.R.drawable.stat_notify_error)
            .resize(width, height)
            .centerCrop()
            .into(target);
}

public static void initPicasso(Context context) {
    if (picasso == null) {
         picassoBuilder = new Picasso.Builder(context);

        try {
            Picasso.setSingletonInstance(picasso);
        } catch (IllegalStateException ignored) {
            // Picasso instance was already set
            // cannot set it after Picasso.with(Context) was already in use
        }
        picassoBuilder.downloader(new OkHttpDownloader(new OkHttpClient())).memoryCache(Cache.NONE).loggingEnabled(true).indicatorsEnabled(true);

        picasso = picassoBuilder.build();
        
    }
}
khushbu
  • 382
  • 1
  • 3
  • 15
0

Nobody will be as dumb as me, but for completeness: if you add a tint color to the image view in your layout file it will obscure the successfully loaded image.

rob5408
  • 2,972
  • 2
  • 40
  • 53