直接使用BarcodeReader 并不能读取,通过不断的实验,采用把位图转换为byte[]后用DatamatrixReader
进行解码
如下:
//把位图转为byte
var bmpData =
img.LockBits(new Rectangle(0, 0, img.Width, img.Height),
ImageLockMode.ReadWrite, img.PixelFormat);
int count =
bmpData.Stride * bmpData.Height;
byte[] pic = new
byte[count];
Marshal.Copy(bmpData.Scan0, pic, 0, count);
img.UnlockBits(bmpData);
LuminanceSource
source = new RGBLuminanceSource(pic, img.Width, img.Height);
BinaryBitmap bitmap
= new BinaryBitmap(new HybridBinarizer(source));
DataMatrixReader
reader = new DataMatrixReader();
Result result =
reader.decode(bitmap);
如下:
//把位图转为byte
