问题描述
我对android很陌生.我想将图像保存到内存中,然后再从内存中检索图像并将其加载到图像视图中.我已使用以下代码成功将图像存储在内部存储器中:
I am quite new to android. I want to save image to internal memory and later retrieve the image from internal memory and load it to image view. I have successfully stored the image in internal memory using the following code :
void saveImage() {
String fileName="img"+ cnt +".jpg";
//File file=new File(fileName);
try
{
FileOutputStream fOut=openFileOutput(fileName, MODE_PRIVATE);
bmImg.compress(Bitmap.CompressFormat.JPEG, 100, fOut);
}
catch (Exception e)
{
e.printStackTrace();
}
}
此代码用于保存jpg图像.如果我要保存gif图像,该怎么办?请帮我.我只能看到jpg和png的选项.
This code is for saving the jpg image. If I want to save a gif image how can i do that?? Please help me. I can see the options for only jpg and png.
推荐答案
位图仅适用于png,jpg等,并且gif是图像列表,因此您必须将其作为二进制文件使用并使用 FileOutputStream 和write(byte[])
Bitmap only works with png, jpg etc, and gif is a list of images, so you have to work with it as a binary file and use FileOutputStream and write(byte[])
这篇关于在Android内部存储器中存储gif图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!