我想从壁画库的Bitmap获取SimpleDraweeView,并将其保存到SD卡。
SimpleDraweeViewImageView的子类,因此它应支持getDrawable(),但调用此方法将引发ClassCastException

BitmapDrawable bitmapDrawable = (BitmapDrawable) viewHolder.drawee.getDrawable();

ClassCastException: com.facebook.drawee.generic.RootDrawable cannot be cast to android.graphics.drawable.BitmapDrawable


这有什么出路?

最佳答案

莫里森提到的s1rius的回答帮助了我。这是我使用的代码。

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

09-26 05:23