I'm using the MonoDroid port of Zxing, found here:
https://github.com/JohnACarruthers/zxing.MonoDroid

I'm trying to create a QR Code and display it in an ImageView, but I
apparently I have no idea what I'm doing ;-)

QRCodeWriter has an encode method that returns a ByteMatrix. I'm trying to
use BitMapFactory.DecodeByteArray, by flattening out the ByteMatrix into a
standard byte[], but BitMapFactory.DecodeByteArray always returns null. 

Here is my code:

                const byte BLACK = 0;
                const byte WHITE = 255;
                        var height = 100;
                        var width = 100;
                        var writer = new QRCodeWriter();
                        var matrix = writer.encode("http//www.google.com",
com.google.zxing.BarcodeFormat.QR_CODE, width, height);
                        var pixels = new byte[width * height];

                        for (var y = 0; y < height; y++)
                        {
                                var offset = y * width;

                                for (var x = 0; x < width; x++)
                                {
                                        int grayValue = matrix.get_Renamed(y, 
x) & 0xff;
                                        pixels[offset + x] = grayValue == 0 ? 
BLACK : WHITE;
                                }
                        }

                        var bitmap = BitmapFactory.DecodeByteArray(pixels, 0, 
pixels.Length);
                        var imageView = 
FindViewById<ImageView>(Resource.Id.QRCode);

                        imageView.SetImageBitmap(bitmap);

The QRCode I'm generating is short lived, so I'm trying not to save it on
the phone's file system, just display it from memory.  Any help on what I'm
doing wrong or the proper way to do this would be helpful.

Also, apologies in advance, I feel like I'm most likely doing something
obviously stupid, I just don't see it.

Thanks,
Dan




--
View this message in context: 
http://mono-for-android.1047100.n5.nabble.com/Get-Bitmap-from-QRCodeWriter-using-Zxing-Library-tp5711054.html
Sent from the Mono for Android mailing list archive at Nabble.com.
_______________________________________________
Monodroid mailing list
Monodroid@lists.ximian.com

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid

Reply via email to