从可绘制的gif文件保存到手机SD?并在使用后将其从sd中删除 [英] saving gif file from drawable into phone sd? and remove it from sd after usage

查看:133
本文介绍了从可绘制的gif文件保存到手机SD?并在使用后将其从sd中删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究如何将文件从 Drawable 保存到SD卡或电话的内部存储中。诸如一个的所有示例仅针对 PNG 类型,我想从我的可绘制对象中获取 GIF 文件并将其保存到手机sd,然后再从sd中删除使用后。

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 from my drawable and save it into phone sd, and later remove it from sd after usage.

有人请提供代码帮助吗?我很感激!

Anybody please help with the code? I appreciate it!

推荐答案

据我所知, Android上没有这样的本机函数(可能与专利问题有关)。您可以尝试此库以达到您的目的。通常,它的目的是创建动画 GIF ,但仅包含一张图片(框架)的文件也应该可以使用。

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.

因此,假设您要处理非动画 GIF

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

Bitmap someBitmap = [...];
File outputFile = new File("/sdcard/myNewGif.gif");
FileOutputStream fos = null;
try {
    fos = new FileOutputStream(outputFile);
} catch (FileNotFoundException e) {
    e.printStackTrace();
}

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

可以找到库作者的更多示例此处

More examples by the library author can be found here.

这篇关于从可绘制的gif文件保存到手机SD?并在使用后将其从sd中删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆