我对安卓还很陌生。我想将图像保存到内存中,然后从内存中检索图像并将其加载到图像视图中。我已使用以下代码成功将图像存储在内存中:
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 的选项。
位图仅适用于 png、jpg 等,而 gif 是图像列表,因此您必须将其作为二进制文件使用并使用文件输出流 http://docs.oracle.com/javase/1.4.2/docs/api/java/io/FileOutputStream.html and write(byte[])
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)