I am generating QR Codes as RGBImage objects using the following code:
private Image getQRImage(String data, int w, int h)
{
try
{
BitMatrix matrix = new QRCodeWriter().encode(data, BarcodeFormat.QR_CODE, w, h);
int width = matrix.getWidth();
int height = matrix.getHeight();
int[] image = new int[width*height];
int i=0;
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
image[i++] = !matrix.get(x, y) ? 0xffffffff : 0xff000000;
}
}
return new RGBImage(image, width, height);
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
I can display the images that this method returns in a Dialog but when I try displaying them using an ImageViewer they do not display. I have only attempted this in the simulator on Windows though I intend to have iOS, Android and Blackberry implementations.
The code that I am using to attempt to display the image looks like this:
ImageViewer viewer = this.findWWWImageViewer();
Image i = getQRImage("hello", getWidth(), getHeight());
viewer.setImage(i);
Thanks much, in advance, for any assistance.
-Eric