c# - Reading QR Code in an image with zxing -


i'm using c# library reading of qrcodes. lot of samples i've found based off old version of zxing rgbluminancesource constructor still takes in bitmap. in latest version rgbluminancesource takes byte[]. i've tried convert bitmap byte[], decode result null.

here's code used conversion:

private byte[] getrgbvalues(bitmap bmp) {   // lock bitmap's bits.    system.drawing.rectangle rect = new system.drawing.rectangle(0, 0, bmp.width, bmp.height);   system.drawing.imaging.bitmapdata bmpdata = bmp.lockbits(rect, system.drawing.imaging.imagelockmode.readonly, bmp.pixelformat);    // address of first line.   intptr ptr = bmpdata.scan0;    // declare array hold bytes of bitmap.   int bytes = bmpdata.stride * bmp.height;   byte[] rgbvalues = new byte[bytes];   // copy rgb values array.   system.runtime.interopservices.marshal.copy(ptr, rgbvalues, 0, bytes);   bmp.unlockbits(bmpdata);    return rgbvalues; } 

and decode:

bitmap bitmap = bitmap.fromfile(@"c:\qrimages.jpg") bitmap; luminancesource source = new rgbluminancesource(getrgbvalues(bitmap), bitmap.width, bitmap.height);  var binarizer = new hybridbinarizer(source); var binbitmap = new binarybitmap(binarizer); qrcodereader reader = new qrcodereader(); var result = reader.decode(binbitmap); 

somehow result null.

also, our requirement have use image taken camera. i've tried this:

bitmap bitmap = bitmap.fromfile(@"c:\qrimages.jpg") bitmap; barcodereader reader = new barcodereader { autorotate = true, tryharder = true }; result result = reader.decode(bitmap); 

it works qr image download online, if print out image , take picture of phone, try process image, result null.

any suggestions appreciated.

here's image i'm using: qr code image

try capturing photo parallel surface. decode. i've tried.


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -