奶霸000

导航

android 保存Bitmap 到本地 哦

public String saveImage(Bitmap bmp) {

File appDir = new File(Environment.getExternalStorageDirectory(), "Boohee");
if (!appDir.exists()) {
appDir.mkdir();
}
String fileName = System.currentTimeMillis() + ".jpg";
File file = new File(appDir, fileName);

try {
FileOutputStream fos = new FileOutputStream(file);
bmp.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return file.getAbsolutePath();
}


用 Zxing 生成二维码 并保存到本地的时候 会看到保存本地的是一张黑色的图 但是用imageview 看到的正常的

因为 imageview 在显示图片时 默认不没有颜色的地方设置成白色了 但是 保存到本地时 它会将没有颜色的地方默认显示成黑色 所有你看到的是全黑色的

解决方案是 在Zxing 生成图片的时候 加上该代码

 


posted on 2016-12-28 18:05  奶霸000  阅读(514)  评论(0编辑  收藏  举报