zoukankan      html  css  js  c++  java
  • 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 生成图片的时候 加上该代码

    
    
  • 相关阅读:
    允许debian wheezy支持IOS7+的iphone.
    openSUSE 国内镜像摘要
    策略模式总结
    顺序串
    WindowState注意事项
    NLP | 自然语言处理
    Using Autorelease Pool Blocks
    NSAutoreleasePool & thread
    oc语言特性
    oc语言基础整理
  • 原文地址:https://www.cnblogs.com/jeno-song/p/6230465.html
Copyright © 2011-2022 走看看