5

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

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

    MediaStore.Images.Media.insertImage(
                                    getActivity().getContentResolver(), bitmap,
                                    "XXX", "Image1"); 

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

你知道我该怎么做吗?

4

2 回答 2

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();
            }

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

于 2016-06-06T19:01:08.167 回答
1

位图是单个图像,因此 GIF 不适用于此 API。要保存 GIF,您需要将 gif 下载到外部存储上的文件中,然后通知 MediaScanner 进行扫描。然后它将显示在画廊中。

于 2014-11-19T21:23:42.100 回答