将gif保存到android gallery
使用图像加载器在ImageView中显示gif文件 我使用此代码将jpg图像保存到gallery中将gif保存到android gallery,android,gif,android-gallery,ion,Android,Gif,Android Gallery,Ion,使用图像加载器在ImageView中显示gif文件 我使用此代码将jpg图像保存到gallery中 MediaStore.Images.Media.insertImage( getActivity().getContentResolver(), bitmap, "XXX", "Image1"); File file = new File(
MediaStore.Images.Media.insertImage(
getActivity().getContentResolver(), bitmap,
"XXX", "Image1");
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文件
你知道我如何才能做到这一点吗?位图是单个图像,因此GIF不能与此API一起使用。要保存GIF,您需要将GIF下载到外部存储器上的文件中,然后通知MediaScanner进行扫描。然后它将显示在图库中。您可以使用此代码保存gif
MediaStore.Images.Media.insertImage(
getActivity().getContentResolver(), bitmap,
"XXX", "Image1");
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();
}
此代码将在外部sd卡的缓存目录中保存gif,但在Gallery中不可见。gif.getData()获取此方法的位置gif表示从apimy gif文件中获取的实际gif。gif文件位于外部存储器中,我有路径,即/storage/emulated/0/Android/data//files//xyz gif。现在我想将此文件保存/复制到图像库并在那里显示。如何做到这一点。因为我没有从字符串imagePath和文件中获取.getData()方法。请先告诉我从何处获取此方法getData(),然后告诉我如何在Gallery中显示此方法?我在这里回答了。谢谢