Androidプログラミングは二次元コードの生成と解析を実現します。


本論文の例は、Androidプログラミングによる二次元コードの生成と解析を実現することを述べている。皆さんに参考にしてあげます。具体的には以下の通りです。
直接コードを通して、コードの上に具体的な解析があり、jarがダウンロードのために提供されます。二次元コードJarパッケージ.rar
テキストから対応する二次元コードを生成します。

//   QR 
private void createImage() {
  try {
   //     core 
   QRCodeWriter writer = new QRCodeWriter();
   String text = qr_text.getText().toString();
   Log.i(TAG, "     :" + text);
   if (text == null || "".equals(text) || text.length() < 1) {
    return;
   }
   //            
   BitMatrix martix = writer.encode(text, BarcodeFormat.QR_CODE,
     QR_WIDTH, QR_HEIGHT);
   System.out.println("w:" + martix.getWidth() + "h:"
     + martix.getHeight());
   Hashtable<EncodeHintType, String> hints = new Hashtable<EncodeHintType, String>();
   hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
   BitMatrix bitMatrix = new QRCodeWriter().encode(text,
     BarcodeFormat.QR_CODE, QR_WIDTH, QR_HEIGHT, hints);
   int[] pixels = new int[QR_WIDTH * QR_HEIGHT];
   for (int y = 0; y < QR_HEIGHT; y++) {
    for (int x = 0; x < QR_WIDTH; x++) {
     if (bitMatrix.get(x, y)) {
      pixels[y * QR_WIDTH + x] = 0xff000000;
     } else {
      pixels[y * QR_WIDTH + x] = 0xffffffff;
     }
    }
   }
   Bitmap bitmap = Bitmap.createBitmap(QR_WIDTH, QR_HEIGHT,
     Bitmap.Config.ARGB_8888);
   bitmap.setPixels(pixels, 0, QR_WIDTH, 0, 0, QR_WIDTH, QR_HEIGHT);
   qr_image.setImageBitmap(bitmap);
  } catch (WriterException e) {
   e.printStackTrace();
  }
}

二次元コード写真から内容を読み取る:

//   QR  
private void scanningImage() {
  Map<DecodeHintType, String> hints = new HashMap<DecodeHintType, String>();
  hints.put(DecodeHintType.CHARACTER_SET, "utf-8");
  //         
  Bitmap bitmap = ((BitmapDrawable) qr_image.getDrawable()).getBitmap();
  RGBLuminanceSource source = new RGBLuminanceSource(bitmap);
  BinaryBitmap bitmap1 = new BinaryBitmap(new HybridBinarizer(source));
  QRCodeReader reader = new QRCodeReader();
  Result result;
  try {
   result = reader.decode(bitmap1, hints);
   //         
   qr_result.setText(result.getText());
  } catch (NotFoundException e) {
   e.printStackTrace();
  } catch (ChecksumException e) {
   e.printStackTrace();
  } catch (FormatException e) {
   e.printStackTrace();
  }
}

ここで述べたように、皆さんのAndroidプログラムの設計に役に立ちます。