Java 是否使用代码在库中保存Gif图像?
我想在android的gallery中保存Gif图像。 我曾多次尝试将gif保存到gallery中,但当我按下save按钮时,它是下载的,但不是gif格式。我不知道是什么问题 请帮我解决这个问题Java 是否使用代码在库中保存Gif图像?,java,android,android-studio,mobile,gif,Java,Android,Android Studio,Mobile,Gif,我想在android的gallery中保存Gif图像。 我曾多次尝试将gif保存到gallery中,但当我按下save按钮时,它是下载的,但不是gif格式。我不知道是什么问题 请帮我解决这个问题 public void saveImageToExternal(String imgName, Bitmap bm) throws IOException { //Create Path to save Image File path = Environment.getE
public void saveImageToExternal(String imgName, Bitmap bm) throws IOException {
//Create Path to save Image
File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES + "/savaimage1.gif"); //Creates app specific folder
path.mkdirs();
File imageFile = new File(path, imgName + ".gif");// Imagename.png
Log.e("msg", imageFile.toString());
FileOutputStream out = new FileOutputStream(imageFile);
Toast.makeText(this, "save", Toast.LENGTH_SHORT).show();
try {
bm.compress(Bitmap.CompressFormat.PNG, 100, out); // Compress Image
out.flush();
out.close();
// Tell the media scanner about the new file so that it is
// immediately available to the user.
MediaScannerConnection.scanFile(MainActivity.this, new String[]{imageFile.getAbsolutePath()}, null, new MediaScannerConnection.OnScanCompletedListener() {
public void onScanCompleted(String path, Uri uri) {
Log.i("ExternalStorage", "Scanned " + path + ":");
Log.i("ExternalStorage", "-> uri=" + uri);
}
});
} catch (Exception e) {
throw new IOException();
}
}
bm.compress(Bitmap.CompressFormat.PNG,100,out)
显然会保存PNG文件,而不是GIF。另外Bitmap bm
与GIF
formatok无关。如何以gif格式保存?要从何处保存?我要从Json保存。