【发布时间】:2016-10-29 06:15:23
【问题描述】:
在 xamarin 中,有人知道如何在使用 MobileBarcodeScanner 扫描条形码或 qrcode 后捕获图像吗?我正在以文本格式获得正确的扫描条形码或 qrcode。但是我可以从中获取扫描的图像吗?
【问题讨论】:
标签: asp.net xamarin.forms
在 xamarin 中,有人知道如何在使用 MobileBarcodeScanner 扫描条形码或 qrcode 后捕获图像吗?我正在以文本格式获得正确的扫描条形码或 qrcode。但是我可以从中获取扫描的图像吗?
【问题讨论】:
标签: asp.net xamarin.forms
我不相信 ZXing 会暴露它用于扫描的底层图像数据。如果您需要这种行为,修改 ZXing 来实现它可能会相当容易。
【讨论】:
ZXing不支持退回扫描图。
您需要修改 ZXing 源代码。
我从 Xamarin 论坛找到了解决方案,请阅读此内容。
从这个线程引用如下。
在 Result.cs 类中,添加属性来处理宽度、高度和源图像
public Android.Graphics.YuvImage SourceYuv { get; set; } public int SourceWidth { get; set; } public int SourceHeight { get; set; }在ZXingSurfaceView.cs中修改OnPreviewFrame方法保存原始图像
...at the beginning before the processing var img = new YuvImage(bytes, ImageFormatType.Nv21, cameraParameters.PreviewSize.Width, cameraParameters.PreviewSize.Height, null); ...result calculations... result.SourceWidth = width; result.SourceHeight = height; result.SourceYuv = img;稍后在我们自己的代码中,当我们得到结果时,我们可以轻松地将其保存到文件或做任何我们想做的事情
string filenamefile = DateTime.Now.Ticks.ToString() + ".jpg"; string filename = System.IO.Path.Combine(Values.DownloadsFolder(), filenamefile); Android.Graphics.Rect rect = new Android.Graphics.Rect(0, 0, result.SourceWidth, result.SourceHeight); using (var os = new FileStream(filename, FileMode.CreateNew)) { result.SourceYuv.CompressToJpeg(rect, 100, os); os.Flush(); os.Close(); }
【讨论】: