com.facebook.imagepipeline.bitmaps.TooManyBitmapsException Fresco使用过程中遇到的坑
生活随笔
收集整理的這篇文章主要介紹了
com.facebook.imagepipeline.bitmaps.TooManyBitmapsException Fresco使用过程中遇到的坑
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
? 使用Drawee來顯示圖片時,發現圖片顯示不出來,根據打的log發現?"com.facebook.imagepipeline.bitmaps.TooManyBitmapsException"的異常。
開始時根據異常的意思猜測可能打開的圖片太多導致的,于是設置fresco的最大緩存大小。
private static int MAX_MEM = 30* ByteConstants.MB; private ImagePipelineConfig getConfigureCaches(Context context) {final MemoryCacheParams bitmapCacheParams = new MemoryCacheParams(MAX_MEM,// 內存緩存中總圖片的最大大小,以字節為單位。 Integer.MAX_VALUE,// 內存緩存中圖片的最大數量。 MAX_MEM,// 內存緩存中準備清除但尚未被刪除的總圖片的最大大小,以字節為單位。 Integer.MAX_VALUE,// 內存緩存中準備清除的總圖片的最大數量。 Integer.MAX_VALUE);// 內存緩存中單個圖片的最大大小。 Supplier<MemoryCacheParams> mSupplierMemoryCacheParams = new Supplier<MemoryCacheParams>() {@Override public MemoryCacheParams get() {return bitmapCacheParams; }}; ImagePipelineConfig.Builder builder = ImagePipelineConfig.newBuilder(context); builder.setBitmapMemoryCacheParamsSupplier(mSupplierMemoryCacheParams); return builder.build(); } Fresco.initialize(this,getConfigureCaches(this));然而,并沒有解決問題。看來這并不是由于緩存了太多圖片引起的。百思不得其解之下google了下找的了一個方法,地址如下:
? ? ? ?https://github.com/facebook/fresco/issues/213
? ? ? ? 其中說到了可能是fresco在加載圖片時重新定義了大小引起的。只要的當前類中初始化Fresco時添加下邊的代碼即可。(注意是在當前activity中,不然在Application中可能不起作用)
? ??
ImagePipelineConfig config = ImagePipelineConfig.newBuilder(this).setDownsampleEnabled(true).build(); Fresco.initialize(this,config);? ?問題解決
? ? ?
總結
以上是生活随笔為你收集整理的com.facebook.imagepipeline.bitmaps.TooManyBitmapsException Fresco使用过程中遇到的坑的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android 根据从服务器中获取的rg
- 下一篇: Android 四大组件之——Aciti