我目前正在使用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(在代码中我也试图完全跳过但没有结果),但我不知道如何做到这一点(代码示例在线不起作用:()。
I'm currently using Picasso to download of images like that:
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);I'm even resizing the images but it's still not enough. The problem is that I have an endless listView, so I keep downloading images and after a will the memory get full. Any idea of how to prevent the problem? I thought to enlarge the memoryCache (in the code I have also tried to skip completely but without results), but I have no idea of how to do that (the code example online don't work :( ).
最满意答案
问题在于我正在缓存自己想要更快地制作东西的图像,而不是因为毕加索自己处理这个问题而无缘无故地挤了堆。 所以,只是删除了优化,我们走了。
The problem was that I was caching myself the images thinking to make stuff faster, instead I was crowding the heap for no reason since Picasso handles itself this problem. So, just erased the optimizations and here we go.
更多推荐
发布评论