【问题标题】:Loading large images using Picasso使用毕加索加载大图像
【发布时间】:2017-08-18 21:04:20
【问题描述】:

我正在尝试使用毕加索加载大图像

public static final int MAX_WIDTH= 500;
public static final int MAX_HEIGHT= 500;

 Picasso.with(imageView.getContext())
                .load(Utils.imagePath(list.get(position).getImage()))
                .resize(MAX_WIDTH,MAX_HEIGHT)
                .onlyScaleDown()
                .memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE)
                .into(imageView);

但我得到了致命异常:java.lang.OutOfMemoryError 上面的代码,我试图加载的图像与下面的图像完全一样

我应该从后端调整图像的大小还是我可以做些什么来避免这种情况?任何帮助将不胜感激。

【问题讨论】:

    标签: android performance android-imageview picasso


    【解决方案1】:

    尝试大堆。在您的manifest 文件中插入android:largeheap="true"

    <application
        android:name=".MyApplication"
        .....
        .....
        android:largeHeap="true"
        .....
        .....
        android:theme="@style/AppTheme" >
    </application>
    

    另外,最好使用.fit()

    .fit() - 这将导致延迟执行请求,直到 ImageView 被布置。

    【讨论】:

    • 如果确实对您有帮助,请将其标记为已接受的答案。它会帮助别人
    【解决方案2】:

    在你的适配器中有这个(似乎是),图像加载可以被调用多次,因为适配器有多个绑定视图。

    所以你确定

    .memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE)
    

    ?

    您最好定义一个内存策略,如果您不想存储太多数据,可能会使用较短的内存大小或较短的超时时间。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-29
      • 1970-01-01
      • 1970-01-01
      • 2014-09-26
      相关资源
      最近更新 更多