Save gif to Android gallery

Using https://github.com/koush/ion image Loader to display gif files in ImageView

I save jpg images in the gallery for this code

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

but this method does not work with gif files.

Do you have any ideas how I can do this?

+5
source share
2 answers

You can save the gif with this code

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

This code will save the gif in the cache directory on your external SD card, but will not be displayed in the Gallery.

+2
source

Raster images are single images, so GIFs will not work with this API. To save the GIF, you need to upload the gif to a file on external storage, and then notify MediaScanner of its scan. Then he will appear in the gallery.

+1
source

Source: https://habr.com/ru/post/1207195/


All Articles