Skip to content

Instantly share code, notes, and snippets.

@trajano
Created June 1, 2013 12:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trajano/5690175 to your computer and use it in GitHub Desktop.
Save trajano/5690175 to your computer and use it in GitHub Desktop.
Creating a QR Code using ZXING
import java.io.FileOutputStream;
import java.io.IOException;
import org.junit.Test;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.Writer;
import com.google.zxing.WriterException;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
public class ZXingTest {
@Test
public void createQRCodeToStream() throws WriterException, IOException {
final Writer w = new QRCodeWriter();
final BitMatrix bitMatrix = w.encode("http://www.trajano.net",
BarcodeFormat.QR_CODE, 200, 200);
final FileOutputStream stream = new FileOutputStream("foo.png");
MatrixToImageWriter.writeToStream(bitMatrix, "png", stream);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment