简体   繁体   English

Zxing.Net中的限制扫描区域

[英]Limit scan area in Zxing.Net

I built a UWP XAML control that acts as a barcode/qrcode scanner using the zxing.net library ( http://zxingnet.codeplex.com/ ). 我使用zxing.net库( http://zxingnet.codeplex.com/ )构建了一个充当条形码/ qrcode扫描程序的UWP XAML控件。 The control works fine, it previews the camera on the device and then captures a frame and let zxing process it. 该控件工作正常,它可以预览设备上的相机,然后捕获帧并让zxing处理它。 All a user has to do is to place it in a page and tell it what type of barcode to scan. 用户要做的就是将其放置在页面中并告诉其要扫描的条形码类型。

I am just facing one problem: How can I limit the scan area to the center of the captured frame? 我只面临一个问题:如何将扫描区域限制在捕获帧的中心? Sometimes there are multiple barcodes in the image and the library returns a result from one of the barcodes but I am interested in the barcode that is in the middle of the frame. 有时图像中有多个条形码,并且库从其中一个条形码返回结果,但是我对位于框架中间的条形码很感兴趣。

Is this possible with zxing.net? zxing.net有可能吗? If so, how can I limit the scan area? 如果可以,如何限制扫描范围?

I don't know what code are you using. 我不知道您在使用什么代码。 But I can give a hint based on my UWP barcode scanner 但是我可以根据我的UWP条码扫描器给出提示

Inside CapturePhotoFromCameraAsync() Task you can find code that take "screenshot" frame from camera: 在CapturePhotoFromCameraAsync()任务内部,您可以找到从相机拍摄“屏幕快照”帧的代码:

 VideoFrame videoFrame = new VideoFrame(BitmapPixelFormat.Bgra8, (int)_width, (int)_height);
 await mediaCapture.GetPreviewFrameAsync(videoFrame);

You can get there SoftwareBitmap and eben convert to WritableBitmap. 您可以在此处找到SoftwareBitmap,然后将eben转换为WritableBitmap。

 SoftwareBitmap sb = videoFrame.SoftwareBitmap;
 WriteableBitmap bitmap = new WriteableBitmap(sb.PixelWidth, sb.PixelHeight);

But now there is another question how to crop WriteableBitmap (you can find solution on SO or MSDN - it's not short) and how to convert back to SoftwareBitmap. 但是现在还有另一个问题,如何裁剪WriteableBitmap(可以在SO或MSDN上找到解决方案-这并不短),以及如何转换回SoftwareBitmap。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM