2

I want to get Bitmap from SimpleDraweeView of Fresco lib, and save it to SD Card. SimpleDraweeView is child class of ImageView so it should support getDrawable() but calling this method throws ClassCastException

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

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

What is the wayout for this?

Jay Donga
  • 431
  • 5
  • 16
  • Can you explain with respect to the main diagram on this page: http://frescolib.org/docs/intro-image-pipeline.html what you are trying to accomplish. – Morrison Chang Jan 30 '17 at 16:53
  • After bitmap is rendered on SimpleDraweeView, that is the last stage, I want to extract the Image on View as bitmap. – Jay Donga Jan 30 '17 at 16:59
  • Found this SO question http://stackoverflow.com/q/30751577/295004 and this answer looks promising: http://stackoverflow.com/a/31769964/295004 – Morrison Chang Jan 30 '17 at 17:13
  • Thanks Morrison for your effort. I will test this and let you know. – Jay Donga Jan 30 '17 at 17:39

1 Answers1

3

s1rius's answer mentioned by Morrison helped me. Here's the code that I used.

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");
}

Then I copied cacheFile into savedImageFile.

Jay Donga
  • 431
  • 5
  • 16