我想从Fresco lib的Bitmap
获取SimpleDraweeView
,并将其保存到SD卡。
SimpleDraweeView
是ImageView
的子类,因此它应该支持getDrawable()
,但调用此方法会抛出ClassCastException
BitmapDrawable bitmapDrawable = (BitmapDrawable) viewHolder.drawee.getDrawable();
ClassCastException: com.facebook.drawee.generic.RootDrawable cannot be cast to android.graphics.drawable.BitmapDrawable
这是什么意思呢?
答案 0 :(得分:2)
ImageRequest downloadRequest = ImageRequest.fromUri(uri);
CacheKey cacheKey = DefaultCacheKeyFactory.getInstance().getEncodedCacheKey(downloadRequest, context);
if (ImagePipelineFactory.getInstance().getMainFileCache().hasKey(cacheKey)) {
BinaryResource resource = ImagePipelineFactory.getInstance().getMainFileCache().getResource(cacheKey);
File cacheFile = ((FileBinaryResource) resource).getFile();
File savedImageFile = new File(Constants.APP_PATH_SAVED_QUOTES, "M1iS1" + "_" + currentPosition + ".jpg");
}
然后我将cacheFile
复制到savedImageFile
。