【问题标题】:Downloading a lot of images with Picasso - Out of memory使用毕加索下载大量图像 - 内存不足
【发布时间】:2014-10-17 17:00:07
【问题描述】:

我目前正在使用 Picasso 下载这样的图像:

ImageView imageView = (ImageView) rootView.findViewById(R.id.imagePreview);
imageView.setAdjustViewBounds(true);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);

Transformation transformation = new Transformation() {

    @Override public Bitmap transform(Bitmap source) {
        int targetHeight = 500;

        double aspectRatio = (double) source.getWidth() / (double) source.getHeight();
        int targetWidth = (int) (targetHeight * aspectRatio);
        Bitmap result = Bitmap.createScaledBitmap(source, targetWidth, targetHeight, false);
        if (result != source) {
            // Same bitmap is returned if sizes are the same
            source.recycle();
        }
        return result;
     }

     @Override public String key() {
         return "transformation" + " desiredWidth";
     }
};

RequestCreator requestCreator;
Picasso picasso = Picasso.with(context);
requestCreator = picasso
                    .load(resource)
                    .transform(transformation)
                    .skipMemoryCache()
                    .error(R.drawable.ic_placeholder_ricerca);

我什至调整了图像的大小,但这还不够。问题是我有一个无穷无尽的listView,所以我一直在下载图像,然后内存就会变满。知道如何预防这个问题吗?我想扩大memoryCache(在代码中我也尝试过完全跳过但没有结果),但我不知道该怎么做(网上的代码示例不起作用:()。

【问题讨论】:

    标签: android android-image picasso


    【解决方案1】:

    问题是我正在缓存自己的图像,以使事情变得更快,相反,我无缘无故地挤满了堆,因为毕加索自己处理了这个问题。因此,只需删除优化即可。

    【讨论】:

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