我想从图库中的照片解码qr代码。如果我选择一张只包含二维码的照片,那么它可以正常使用,但如果它是一张普通照片,其中包含qr,结果为空。我做错了什么?
BitmapImage bitmap = new BitmapImage();
bitmap.SetSource(e.ChosenPhoto);
WriteableBitmap wb = new WriteableBitmap(bitmap);
BarcodeReader reader = new BarcodeReader {AutoRotate = true, TryHarder = true};
Result result = reader.Decode(wb);
PS。我尝试用这种方式解码亮度源:
var writeableBmp = new WriteableBitmap(1, 1);
writeableBmp.SetSource(e.ChosenPhoto);
writeableBmp = new WriteableBitmap(writeableBmp.PixelWidth, writeableBmp.PixelHeight);
e.ChosenPhoto.Position = 0;
writeableBmp.SetSource(e.ChosenPhoto);
LuminanceSource ls;
byte[] buffer = new byte[writeableBmp.PixelHeight * writeableBmp.PixelWidth];
using (MemoryStream ms = new MemoryStream())
{
int read;
while ((read = e.ChosenPhoto.Read(buffer, 0, buffer.Length)) > 0)
{
ms.Write(buffer, 0, read);
}
ls = new RGBLuminanceSource(ms.ToArray(), writeableBmp.PixelWidth, writeableBmp.PixelHeight,
RGBLuminanceSource.BitmapFormat.Gray8);
}
但如果我这样做,它甚至无法读取先前有效的qr代码。