解决方案 »

  1.   

    Bitmap里没有数据就是黑的
    楼主再仔细看看代码
      

  2.   


    我生成的bitmap在imageview里面是可以使用的,但是保存成文件就不行了,不知道为啥
      

  3.   


    在imageview里面可以显示,但是保存成图片不行,为啥呢
      

  4.   

    qrCodeBitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
    这个参数怎么可能是100呢?是100就表示图片全没啦。
    参数改为0,表示图片没有压缩,是100%
    参数改为30,表示图片压缩到原来的70%
    楼主参数是100,则表示图片压缩到原来的0%,  图片当然 没有啦。
      

  5.   

    出现的问题可能原因:
    1 没有任何数据写入到图片中
    2 图片数据写入编码与读取编码不一致
    qrCodeBitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);中的100指图片的质量,并非缩放比,android API对此描述如下:
    quality  Hint to the compressor, 0-100. 0 meaning compress for small size, 100 meaning compress for max quality. Some formats, like PNG which is lossless, will ignore the quality setting
      

  6.   


    有可能是你说的编码不一致的问题,怎么解决呢? 在imageView 显示的正常保存本低有问题
      

  7.   

    找到bug的原因了,我在网上找到二维码生成图片的代码,拿过来直接用的,没有仔细检查,虽然在imageview中显示正常,视音频imageview中没有颜色的位置默认使用的是白色的替代的,但是保存成png后,没有颜色的位置使用的是黑色替代的,所以会看到生成的图片是全黑的,下面上代码
    public static Bitmap createQRCode(String str,int widthAndHeight) throws WriterException {
    Hashtable<EncodeHintType, String> hints = new Hashtable<EncodeHintType, String>();  
            hints.put(EncodeHintType.CHARACTER_SET, "utf-8"); 
    BitMatrix matrix = new MultiFormatWriter().encode(str,
    BarcodeFormat.QR_CODE, widthAndHeight, widthAndHeight);
    int width = matrix.getWidth();
    int height = matrix.getHeight();
    int[] pixels = new int[width * height];

    for (int y = 0; y < height; y++) {
    for (int x = 0; x < width; x++) {
    if (matrix.get(x, y)) {
    pixels[y * width + x] = BLACK;
    }else{
    pixels[y * width + x] = WHITE;
    }
    }
    }
    Bitmap bitmap = Bitmap.createBitmap(width, height,
    Bitmap.Config.RGB_565);
    bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
    return bitmap;
    }
    代码中  pixels[y * width + x] = WHITE;
    这段嗲吗是我自己后加上的,加上之后就能显示了,谢谢楼上各位朋友的好心帮助,