Creating colored QR Codes and NotFoundException while decoding a colored decoded QRCode image

103 views
Skip to first unread message

Rakshit Ashtekar

unread,
Apr 10, 2015, 4:54:08 PM4/10/15
to zx...@googlegroups.com
Hello everyone,

Is there any rule where the user can only use certain color combinations (background and foreground color) to create colored QR Code? I tried to spend some time in debugging the zxing library (inside HybridBinarizer.class) and my limited investigation suggests that there needs to be certain value of luminescence ??

I am working on a project where I need to create colored QR Code. I am using MultiFormatWriter to encode the message and then using Graphics2D to write the image to BitMatrix. Below is the code snippet:

matrix = MultiFormatWriter(...)
int matrixWidth = matrix.getWidth();
image = new BufferedImage(matrixWidth, matrixWidth, typeModel);
image.createGraphics();
Graphics2D graphics = (Graphics2D) image.getGraphics();
Font font = new Font(Font.SANS_SERIF, Font.PLAIN, 18);
graphics.setFont(font);
graphics.setColor(qrCode.getBgColor()); // R=0, G=255, B=0
graphics.fillRect(0, 0, matrixWidth, matrixWidth);
// Color mainColor = new Color(51, 102, 153);
graphics.setColor(qrCode.getFgColor()); // R=128, G=128, B=0

// Write Bit Matrix as image
for (int i = 0; i < matrixWidth; i++) {
for (int j = 0; j < matrixWidth; j++) {
if (matrix.get(i, j)) {
graphics.fillRect(i, j, 1, 1);
}
}
}

Before I create the final QR Code image, I am decoding the image to fetch the decoded message and comparing it with the original message. I am getting NotFoundException while decoding the image.

try {
LuminanceSource source = new BufferedImageLuminanceSource(image);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
Hashtable < DecodeHintType, Object > decodeHints = new Hashtable < DecodeHintType, Object > ();
decodeHints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
List < BarcodeFormat > barCodeFormat = new ArrayList < BarcodeFormat > ();
barCodeFormat.add(BarcodeFormat.QR_CODE);
decodeHints.put(DecodeHintType.POSSIBLE_FORMATS, barCodeFormat);
Result result = new MultiFormatReader().decode(bitmap, decodeHints);
return result;
} catch (NotFoundException nfe) {
nfe.printStackTrace();
return null;
}

I could decode the image with other standard RGB colors where the background was in light shade than the foreground color.

Any pointers would be helpful..

Thanks in advance,
R

solon

unread,
May 5, 2015, 12:29:23 PM5/5/15
to zx...@googlegroups.com
To let us better understand the problem, would you mind putting one or two "colored QR codes" you are working on?

As far as I know, the scanner will convert the image to gray scale and binarize the image into a binary image before passing to the decoder.

If the QR code is the same after binarizing, the color of the QR code should not affect the decoding result.

Rakshit Ashtekar於 2015年4月11日星期六 UTC+8上午4時54分08秒寫道:
Reply all
Reply to author
Forward
0 new messages