2014-09-25 118 views
5

我使用Picasso将Url中约250-500 Kb(1600x〜1200)的JPG加载到ImageView中。用Picasso缓慢加载大图像

Picasso.with(getApplicationContext()) 
.load(stringURL)       
.placeholder(R.drawable.holder).error(R.drawable.holder) 
.into(image) 

我的ImageView:

<ImageView 
android:id="@+id/image" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:layout_alignParentTop="true" 
android:layout_centerInParent="true" 
android:layout_marginTop="0dip" 
android:adjustViewBounds="true" 
android:cropToPadding="false" 
android:scaleType="fitCenter" 

/>;

问题是,第一次加载的图像是非常非常慢(约20秒),CPU消耗高,所以内存分配。 对于单个映像,LogCat显示了“为7601812字节分配增长堆(碎片大小)为56.789”。

与图像缓存有关吗?有一种方法可以禁用缓存并直接将原始图像下载到ImageView中?

下载从IPhone相同的图像到双应用程序是瞬时...

+0

这就是7MB的图像。你的日志告诉你1600x1200x4 = 7.6MB。这将需要时间来解码。尝试使用'fit()'或'resize()'或最后使用'RGB_565'配置。 – dnkoutso 2015-01-18 17:20:41

回答

0

我切换到截击。加载相同的图像现在只需要很短的时间。

3

如果您使用fit()resize()应该解决您的问题。我目前将数百个非常大的jpg文件加载到一个GridLayout中,并且没有问题。