Skip to content Skip to sidebar Skip to footer

How To Save Image To Sdcard When Using Fresco?

I am using Fresco to download and display Gifs in my app. I want to save the image to sdcard when click it, but i can't figure out how to do it. final View view = inflater.inflate(

Solution 1:

You can do like this

ImageRequestdownloadRequest= ImageRequest.fromUri(uri);
CacheKeycacheKey= DefaultCacheKeyFactory.getInstance().getEncodedCacheKey(downloadRequest);
if (ImagePipelineFactory.getInstance().getMainDiskStorageCache().hasKey(cacheKey)) {
    BinaryResourceresource= ImagePipelineFactory.getInstance().getMainDiskStorageCache().getResource(cacheKey);
    FilecacheFile= ((FileBinaryResource) resource).getFile();
    FileInputStreamfis=newFileInputStream(cacheFile);
    ImageFormatimageFormat= ImageFormatChecker.getImageFormat(fis);
    switch (imageFormat) {
        case GIF:
        //copy cacheFile to sdcardbreak;
    }
}

Solution 2:

You can use the image pipeline directly to extract your GIF from disk cache.

Then you can use Java File methods to write it to the file system.

Post a Comment for "How To Save Image To Sdcard When Using Fresco?"