条形码Reader.Decode(writeableBitMap) 返回 null [英] barcodeReader.Decode(writeableBitMap) returning null

查看:32
本文介绍了条形码Reader.Decode(writeableBitMap) 返回 null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用 CASE39 条码时,我总是从解码中返回 null

When I try a barcode that I've told is a CASE39 barcode I always get null returned from the decode

  if (cbBarcode.IsChecked == true)
            {
                var photoStorageFile = await KnownFolders.PicturesLibrary.CreateFileAsync("scan.jpg", CreationCollisionOption.GenerateUniqueName);

                Size aspectRatio = new Size(3, 1);
                dialog.PhotoSettings.CroppedAspectRatio = aspectRatio;
                StorageFile file = await dialog.CaptureFileAsync(CameraCaptureUIMode.Photo);
                string ImageValues = "bbc_photo" + x;
                var stream = await file.OpenReadAsync();
                // initialize with 1,1 to get the current size of the image
                var writeableBmp = new WriteableBitmap(1, 1);
                writeableBmp.SetSource(stream);
                // and create it again because otherwise the WB isn't fully initialized and decoding
                // results in a IndexOutOfRange
                writeableBmp = new WriteableBitmap(writeableBmp.PixelWidth, writeableBmp.PixelHeight);
                stream.Seek(0);
                writeableBmp.SetSource(stream);
                var result = ScanBitMap(writeableBmp);
                if (result != null)
                {
                    MessageDialog dialog2 = new MessageDialog(result.Text.ToString());
                    await dialog2.ShowAsync();
                    //photoStorageFile = writeableBmp;
                }
                else
                {
                    MessageDialog errdialog = new MessageDialog("Error reading barcode.. Please try again");
                    await errdialog.ShowAsync();
                }
                return;



     private Result ScanBitMap(WriteableBitmap writeableBmp)
     {
         var barcodeReader = new BarcodeReader
         {
             AutoRotate = true,
             Options = new DecodingOptions
             {
                 TryHarder = true,
                 // restrict to one or more supported types, if necessary
                 PossibleFormats = new []
                  {
                    BarcodeFormat.CODE_39
                   }
             }
         };
         var result = barcodeReader.Decode(writeableBmp);

         if (result != null)
         {
             CapturedPhoto.Source = writeableBmp;
         }

         return result;
     }

我最近添加了 Options 的代码,但似乎没有改变来自 Decode 函数的输出.我正在为平板电脑上运行 Windows 8.1 Metro 应用程序 xaml 的应用程序编写此内容.

I recently added the code for Options but nothing seems to be changing the output coming from the Decode function. I am writing this for an app on the tablet that runs windows 8.1 metro app xaml.

推荐答案

这个问题的答案是不要使用 Zxing 条码扫描器 sdk 并下载 Easy Barcode Scanner Free windows 应用程序,因为它会解码条码并且更容易实现.

The answer to this question is to not use Zxing barcode scanner sdk and download the Easy Barcode Scanner Free windows app because it will decode barcodes and is easier to implement.

这篇关于条形码Reader.Decode(writeableBitMap) 返回 null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆