Skip to content Skip to sidebar Skip to footer

Saving Gif File From Drawable Into Phone Sd? And Remove It From Sd After Usage

I have been searching on how to save file from Drawable into sd card OR phone's internal storage. All examples such as this one showed only for PNG type, I want to get GIF file fro

Solution 1:

As far as i know there isn't such a native function on Android (maybe related to patent issues). You may try this library for your purpose. Usually its meant to create animated GIF but a file with just one picture (frame) should also work.

So a complete example could be like this assuming you are dealing with a non animated GIF:

BitmapsomeBitmap= [...];
FileoutputFile=newFile("/sdcard/myNewGif.gif");
FileOutputStreamfos=null;
try {
    fos = newFileOutputStream(outputFile);
} catch (FileNotFoundException e) {
    e.printStackTrace();
}

if (fos != null) {
    AnimatedGifEncodergifEncoder=newAnimatedGifEncoder();
    gifEncoder.start(fos);
    gifEncoder.addFrame(someBitmap);
    gifEncoder.finish();
}

More examples by the library author can be found here.

Post a Comment for "Saving Gif File From Drawable Into Phone Sd? And Remove It From Sd After Usage"