将gif保存到android库

Jeh*_*had 5 android gif android-gallery android-ion

使用https://github.com/koush/ion image Loader将gif文件显示到ImageView中

我通过此代码将jpg图像保存到图库中

    MediaStore.Images.Media.insertImage(
                                    getActivity().getContentResolver(), bitmap,
                                    "XXX", "Image1"); 
Run Code Online (Sandbox Code Playgroud)

但这种方式不适用于gif文件.

你知道我怎么能做到这一点?

Rah*_*mar 2

您可以使用此代码保存 gif

  File file = new File(getBaseContext().getExternalCacheDir(),
                    "gif_name"+ ".gif");
            try {
                FileOutputStream fos = new FileOutputStream(file);
                fos.write(gif.getData());//gif is gif image object
                fos.flush();
                fos.close();
            } catch (IOException ioe) {
                ioe.printStackTrace();
            }
Run Code Online (Sandbox Code Playgroud)

此代码会将 gif 保存在外部 SD 卡的缓存目录中,但在图库中不可见。