fresco icon indicating copy to clipboard operation
fresco copied to clipboard

How can I save an image to sd card?

Open y11t opened this issue 11 years ago • 4 comments

How can I save an image to sd card? What to do with cacheFile?

public void DownloadClicked(String url){
        Uri uri = Uri.parse(url);
        ImageRequest downloadRequest = ImageRequest.fromUri(uri);
        CacheKey cacheKey = DefaultCacheKeyFactory.getInstance().getEncodedCacheKey(downloadRequest);
        if (ImagePipelineFactory.getInstance().getMainDiskStorageCache().hasKey(cacheKey)) {
            BinaryResource resource = ImagePipelineFactory.getInstance().getMainDiskStorageCache().getResource(cacheKey);
            File cacheFile = ((FileBinaryResource) resource).getFile();
            try{
                FileInputStream fis = new FileInputStream(cacheFile);
                ImageFormat imageFormat = ImageFormatChecker.getImageFormat(fis);
                switch (imageFormat) {
                    case GIF:
                        //copy cacheFile to sdcard
                        break;
                }
            }catch (Exception e){
                e.printStackTrace();
            }

        }
    } 

y11t avatar Aug 18 '15 10:08 y11t

Please read our documentation Using the Image Pipeline Directly and DataSources and DataSubscribers.

Do not access the disk cache directly, but submit the image request and subscribe your data subscriber as explained in the "get encoded image" example in the documentation.

plamenko avatar Aug 18 '15 14:08 plamenko

what is work for executor there? while simply downloading images from bitmap subscriber

Iamasthme avatar Sep 26 '15 19:09 Iamasthme

I found they mention it in https://github.com/facebook/fresco/issues/265. However, the doc has not get updated. I found it is runnable with this: new Executor() { @Override public void execute(Runnable command) { command.run(); } }

SiBorya avatar Dec 04 '15 07:12 SiBorya

How do you retrieve the GIF file from the subscriber?

leeyikjiun avatar Feb 06 '16 01:02 leeyikjiun