我想从.png文件导入QR码并使用Zxing.Mobile.net(https://www.nuget.org/packages/ZXing.Net.Mobile/和https://www.nuget.org/packages/ZXing.Net.Mobile.Forms)对其进行解码。阅读Xamarin Forms与Zxing的QR码
如果我使用ZXing.Mobile.MobileBarcodeScanner
类扫描QR码,解码将按需要工作,但是,从文件导入时,Qr代码阅读器(ZXing.QrCode.QRCodeReader()
)解码函数始终返回null。
当我使用xamarin表单时,每个平台处理位图/图像创建,便携部分处理其余部分(Zxing BinaryBitmap创建和解码)。
//Store rawBytes and image demensions
PotableBitmap bMap = DependencyService.Get<IBitmap>().FileToBitmap(filePath);
RGBLuminanceSource source = new RGBLuminanceSource(bMap.RgbBytes, bMap.Width, bMap.Height, RGBLuminanceSource.BitmapFormat.RGB32);
HybridBinarizer binarized = new HybridBinarizer(source);
BinaryBitmap bitmap = new BinaryBitmap(binarized);
var reader = new ZXing.QrCode.QRCodeReader();
data = reader.decode(qrCodeBitmap); // This is always null
的DependencyService将调用平台特定的功能,此刻我与Andorid的工作,所以,功能如下:
public PortableBitmap FileToBitmap(string ms)
{
var bytes = File.ReadAllBytes(ms);
Android.Graphics.Bitmap bMap = BitmapFactory.DecodeByteArray(bytes, 0, bytes.Length);
int[] intArray = new int[bMap.Width * bMap.Height];
bMap.GetPixels(intArray, 0, bMap.Width, 0, 0, bMap.Width, bMap.Height)
List<byte> result = new List<byte>();
foreach (int intRgb in intArray)
{
Color pixelColor = new Color(intRgb);
result.Add(pixelColor.R);
result.Add(pixelColor.G);
result.Add(pixelColor.B);
}
return new PortableBitmap(result.ToArray(), bMap.Width, bMap.Height);
}
我已经经历了一些职位,这样看着有同样的问题,并曾尝试以下:
- 使用BitmapLuminanceSource:仍然返回null,需要使用另一个库的
- 使用不同的位图格式的RGBLuminanceSource:RGB32,BGR32,ARGB32,ABGR32
- 试过不同二值化(每次改变FileToBitmap功能),
GlobalHistogramBinarizer()
- 经过通过阅读和wrinting认为文件正在被正确地读出回到一个文件。更难提示
- 我已经使用
MultiFormatReader()
与纯条形码尝试和尝试,我也调试库的源代码,并从我的理解,它只是无法找到导入的图像中的QR码。没有例外被抛出。
这里就是返回NULL由:
private FinderPattern[] selectBestPatterns()
{
int startSize = possibleCenters.Count;
if (startSize < 3)
{
// Couldn't find enough finder patterns
return null; // It returns here
}
...
在线斑马线解码器(https://zxing.org/w/decode.jspx)可以解码QR码我正确的测试。这是我测试的QR码:
您的问题的Java解决方案,它可能会帮助把你放在正确的路径,https://stackoverflow.com/questions/3422651/decoding-qr-code-from-image-stored-on-the-phone -with-zxing-on-android-phone – Kevin
谢谢你的链接,但我已经试过这个解决方案没有成功 – PMARSH