ストアアプリでQRコードを読み取るライブラリを探していたらZXing.NETというライブラリがあったのでメモ。
まずはNuGetから導入。
使い方はHow to use zxing in WinRT applicationが参考になります。
WriteableBitmapにして利用する必要があるので、WebカメラなどからQRコードを読み取る場合定期的に画像に変換してあげる。
var property = ImageEncodingProperties.CreateJpegXR();
property.Width = 480;
property.Height = 360;
var rndStream = new InMemoryRandomAccessStream();
try
{
await capture.CapturePhotoToStreamAsync(property, rndStream);
rndStream.Seek(0);
BitmapImage bitmap = new BitmapImage();
bitmap.SetSource(rndStream);
WriteableBitmap writeableBitmap = new WriteableBitmap(600, 600);
// オリジナル画像を読み込む
writeableBitmap = await writeableBitmap.FromStream(rndStream);
IBarcodeReader reader = new BarcodeReader();
// load a bitmap
// detect and decode the barcode inside the bitmap
var result = reader.Decode(writeableBitmap);
if (result != null)
{
// QRコードの値が取れた
}
Please give us your valuable comment