2015-05-20 39 views
0

对不起,我的英语。我无法扫描qr图像,我有这个“???????”。我使用zxing库。我尝试但没有成功。贝娄我的代码。字符串等于俄语字符集。我不知道为什么扫描实例符号要??????。无法扫描显示图像字符集qr zxing android

final QRCodeWriter writer = new QRCodeWriter(); 
ImageView tnsd_iv_qr = (ImageView)findViewById(R.id.qrImage); 
Charset charset = Charset.forName("UTF-8"); 
CharsetEncoder encoder = charset.newEncoder(); 
byte[] b = null; 
try { 
    // Convert a string to UTF-8 bytes in a ByteBuffer 
    ByteBuffer bbuf = encoder.encode(CharBuffer.wrap(summ.getText().toString() + "/" 
      + getNumber.substring(1) + "/" 
      + getName + "/" 
      + getIdDepartament + "/" 
      + getIdUser + "/" 
      + getSpinnerItem)); 
    b = bbuf.array(); 
} catch (CharacterCodingException e) { 
    // 
} 

String data; 

try { 
    data = new String(b, "UTF-8"); 
    Hashtable<EncodeHintType, String> hints = new Hashtable<EncodeHintType, String>(2); 
    hints.put(EncodeHintType.CHARACTER_SET, "UTF-8"); 

     ByteMatrix bitMatrix = writer.encode( data 

       ,BarcodeFormat.QR_CODE, 512, 512, hints); 

     int width = 512; 
     int height = 512; 
     Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565); 
     for (int x = 0; x < width; x++) { 
      for (int y = 0; y < height; y++) { 
       if (bitMatrix.get(x, y)==0) 
        bmp.setPixel(x, y, Color.BLACK); 
       else 
        bmp.setPixel(x, y, Color.WHITE); 
      } 
     } 
     tnsd_iv_qr.setImageBitmap(bmp); 
    } catch (WriterException | UnsupportedEncodingException e) { 
     e.printStackTrace(); 
    } 

回答

1

我修复此行

data = new String(b, "ISO-8859-1"); 
         Hashtable<EncodeHintType, String> hints = new Hashtable<EncodeHintType, String>(2); 
         hints.put(EncodeHintType.CHARACTER_SET, "ISO-8859-1"); 

及其工作!