这个方法帮助我将图像从数据库显示到imgview。 那么如何将其保存到SD卡上呢?
private Bitmap setImage(String base64String) {
Bitmap bmp = null;
try {
if (base64String == null || base64String.equals("")) {
} else {
byte[] decodedString = Base64.decode(base64String, Base64.DEFAULT);
bmp = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
}
} catch (Exception e) {
e.printStackTrace();
}
return bmp;
}
eclipse 安卓2.2
最佳答案
从您的方法中获取位图返回,您可以将该位图存储到SD卡中。
在android中我们可以通过类似的方式保存位图。
然后您必须从 SD 卡获取目录(文件对象),例如:
File deviceSdcardDirectory = Environment.getExternalStorageDirectory();
接下来,创建用于图像存储的特定文件:
File image = new File(deviceSdcardDirectory, "file_name.png");
之后,您只需编写位图:
// Encode the file as a PNG image.
FileOutputStream outStream;
try {
outStream = new FileOutputStream(image);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, outStream);
/* 100 to keep full quality of the image */
outStream.flush();
outStream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
不要忘记在 list 文件中添加以下权限:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
关于android - 如何将图像从数据库导出到SD卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22062776/