android 保存Bitmap 到本地 哦

☆樱花仙子☆ 提交于 2020-02-05 00:24:30
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 生成图片的时候 加上该代码

 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!