Android Picasso Image无法加载

xos*_*uma 9 android imageview picasso

有两种情况我加载图像,第一种是直接从互联网上加载,第二种是加载在设备中下载的图像.每当我加载时,显示10个图像中的8~9个,并且1-2个丢失.我看到解码返回false,并尽可能地坚持google,但无法提出.

  1. WAIT_FOR_CONCURRENT_GC阻止了22ms
  2. WAIT_FOR_CONCURRENT_GC阻止了20ms
  3. GC_FOR_ALLOC释放718K,31%免费9948K/14256K,暂停49ms,总计51ms
  4. D/skia:--- decoder-> decode返回falseGC_CONCURRENT释放1370K,30%免费10081K/14256K,暂停3ms + 2ms,总计33ms
  5. GC_FOR_ALLOC释放916K,30%免费10029K/14256K,暂停66ms,总计67ms

这是我用来加载Picasso的代码:

        Picasso.with(activity)
            .load(path)
            .placeholder(R.drawable.thumbnail_placeholder)
            .resize(width,height)
            .into(imageView);
Run Code Online (Sandbox Code Playgroud)

任何想法如何解决这个问题?我每次在屏幕上加载图像时都会调用fit()/ resize().非常感谢,提前感谢!

仅供参考,我在机器,仿真器和真实设备三星Galaxy Tab 3上进行测试,并且在仿真器上没有任何问题,但在真实设备上会出现问题.

更新:

它是由图像的色彩空间引起的,其中未显示的图像是YMCK色彩空间中的图像.

Mat*_*rer 25

您可以使用开启Picasso日志Picasso.with(Context).setLoggingEnabled(true).您可能会看到一条错误消息,其中包含原因.

为了以防万一,还值得记录您正在使用的URL并尝试使用浏览器.

  • 我认为这已更改为`Picasso.get()。setLoggingEnabled(true)` (2认同)

Tar*_*ath 19

在manifestaest中检查Internet权限

<uses-permission android:name="android.permission.INTERNET"/>
Run Code Online (Sandbox Code Playgroud)


dzi*_*kyy 9

在Picasso中,你应该通过url .load()方法从网络加载图片和File类型对象从设备存储加载图片.

因此,如果图片存储在设备上加载,就像这样:

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

并使用此代码从Internet加载图片:

        Picasso.with(activity)
                .load(path)
                .placeholder(R.drawable.thumbnail_placeholder)
                .resize(width,height)
                .into(imageView);
Run Code Online (Sandbox Code Playgroud)


小智 8

尝试将网址开头的“http:”替换为“https:”(如果适用)

(on your String representation of Url).replace("http:", "https:");
Run Code Online (Sandbox Code Playgroud)

对我有用。


Gen*_*tle 6

不知道它是否与此问题相关,但是我的问题通过使用Glide而不是Picasso得以解决。


kam*_*aul 6

您可以使用Picasso.with(Context).setLoggingEnabled(true)启用调试,以便排查确切原因。如果日志中有类似Error 504try using 的内容,请尝试使用

android:usesCleartextTraffic="true"

在清单的应用程序标签中。它对我有用

在这里回答