Xamarin的Android QR-图像ZXing - 不工作
我与Xamarin和MvvmCross项目都有一个核心项目(共享code)。
My project with Xamarin and MvvmCross has a Core-Project (to share code).
在此核心项目,我生成QR-图像,并将其保存到本地驱动器在我的Android应用程序。下面code生成字节的内容(总是一个URL):
In this Core-Project, I generate a QR-Image and save it to the local-drive in my Android-App. The following code generates the bytes for a content (always an url):
var options = new QrCodeEncodingOptions
{
Height = 300,
Width = 300,
Margin = 0,
PureBarcode = true
};
var writer = new BarcodeWriter { Format = BarcodeFormat.QR_CODE, Options = options };
return writer.Write(content);
我保存在我的应用程序,数据目录此字节数组的文件,插件(MvvmCross)。 存在 - 方法返回true,因此该文件是存在的(我希望如此)。
I save this byte-array with the File-Plugin (MvvmCross) in my app-data-dir. The "Exists"-Method returns true, so the file is there (I hope so).
不过,我叫下面的code时,得到一个位图,以显示保存的QR-图像中的活动中,Bitmapfactory返回NULL每次:
But when i call following code to get a bitmap to show the saved qr-image in an activity, the Bitmapfactory returns NULL every time:
// First decode with inJustDecodeBounds=true to check dimensions
var options = new BitmapFactory.Options();
options.InJustDecodeBounds = true;
BitmapFactory.DecodeFile(filepath, options);
// Calculate inSampleSize
options.InSampleSize = CalculateInSampleSize(options, reqWidth, reqHeight);
// Decode bitmap with inSampleSize set
options.InJustDecodeBounds = false;
return BitmapFactory.DecodeFile(filepath, options);
在没有立足之地也不例外。我不知道,怎么回事错了。与其他图像(保存,并以相同的方式装,但是没有生成QR-图像),所有工作正常。
No exception in no place. I have no idea, whats going wrong. With other pictures (saved and loaded in the same way, but no generated qr-image), all works fine.
我用下面的zxing在我的便携式(核心)库: zxing.portable(v4.0.30319) 说明:基于java的吧code扫描图书馆的.NET接口(Java zxing 2014年3月13日15点19分08秒)
I use following zxing in my portable (core) library: zxing.portable (v4.0.30319) Description: port of the java based barcode scanning library for .net (java zxing 13.03.2014 15:19:08)
欢迎任何帮助=)谢谢
但问题是,我实现了QR-形象PCL-库中的发生 - code。在这种设置中,zxing-lib中生成的RAW字节数组(感谢迈克尔对他的帮助)。
The problem was, that I implemented the generation-code of the QR-Image in the PCL-Library. In this setup, the zxing-lib generated a RAW-byte array (thanks to 'Michael' for his help).
解决之道:我只是实现了一个MvvmCross-插件为每个平台。现在zxing-LIB(Android版)生成位图,而不是一个原始字节数组。最后输入的解决方案:的酒吧codeWriter.cs
The solution: I just implemented a MvvmCross-Plugin for each platform. Now the zxing-lib (for android) generates a Bitmap and not a RAW-byte array. Final input for the solution: BarcodeWriter.cs
zxing.portable的默认渲染器还给原始ARGB数据的字节数组。 你应该使用的方法BitmapFactory.De codeByteArray或保存它,然后建立从字节数组支持的文件格式。
The default renderer of zxing.portable gives back a byte array of the raw ARGB data. You should use the method BitmapFactory.DecodeByteArray or you build a supported file format from the byte array before saving it.