samedi 1 septembre 2012

Code barre 2d (QRCode)

Il y a Zxing de google
http://code.google.com/p/zxing/

int magnify = 1; //The resolution of the QRCode
 
  QRCodeWriter writer = new QRCodeWriter();
  BitMatrix matrix;
 
  // The QR should be multiplied up to fit, with extra padding if necessary
  int size = 180;
  matrix = writer.encode("Un p'tit bonjour de Tours !", BarcodeFormat.QR_CODE, size, size, null);
 
  //Make the BufferedImage that are to hold the QRCode
  BufferedImage im = new BufferedImage(size, size, BufferedImage.TYPE_INT_RGB);
  im.createGraphics();
  Graphics2D g = (Graphics2D) im.getGraphics();
  g.setColor(Color.WHITE);
  g.fillRect(0, 0, size, size);
 
  //paint the image using the ByteMatrik
  for (int h = 0; h < matrix.getHeight(); h++) {
   for (int w = 0; w < matrix.getWidth(); w++) {
    //Find the colour of the dot
    if (matrix.get(h, w) == false) {
     g.setColor(Color.WHITE);
    } else {
     g.setColor(Color.BLACK);
    }
    //Paint the dot
    g.fillRect(h * magnify, w * magnify, magnify, magnify);
   }
  }
 
  ImageIO.write(im, "png", new File("testQRCodeWriter.png"));

Aucun commentaire:

Enregistrer un commentaire