Rakshit Ashtekar
unread,Apr 10, 2015, 4:54:08 PM4/10/15Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message as abuse
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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