如何使用ZBar阅读器的scanCrop属性? [英] How do I use the scanCrop property of a ZBar reader?

查看:217
本文介绍了如何使用ZBar阅读器的scanCrop属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ZBar SDK for iPhone来扫描条形码。我希望读者只扫描一个特定的矩形而不是整个视图,这样做需要将阅读器的scanCrop属性设置为所需的矩形。

I am using the ZBar SDK for iPhone in order to scan a barcode. I want the reader to scan only a specific rectangle instead of the whole view, for doing that it is needed to set the scanCrop property of the reader to the desired rectangle.

我很难理解必须设置的矩形参数。

I'm having hard time with understanding the rectangle parameter that has to be set.

有人可以告诉我,如果在肖像视图中我应该给出什么矩形作为参数坐标为: CGRectMake(A,B,C,D)

Can someone please tell me what rect should I give as an argument if on portrait view its coordinates would be: CGRectMake( A, B, C, D )?

推荐答案

来自zbar的 ZBarReaderView类文档


CGRect scanCrop

CGRect scanCrop

将在标准化图像坐标中扫描的视频图像区域即可。请注意,视频图像处于横向模式(默认为{{0,0},{1,1}})

The region of the video image that will be scanned, in normalized image coordinates. Note that the video image is in landscape mode (default {{0, 0}, {1, 1}})

坐标所有参数都在一个标准化的浮点数中,从0到1.因此,在标准化值中, theView.width 是1.0, theView.height 是1.0。因此,默认的矩形是{{0,0},{1,1}}。

The coordinates for all of the arguments is in a normalized float, which is from 0 - 1. So, in normalized value, theView.width is 1.0, and theView.height is 1.0. Therefore, the default rect is {{0,0},{1,1}}.

例如,如果我有一个透明的 UIView scanView 命名为我的 readerView 的扫描区域。而不是:

So for example, if I have a transparent UIView named scanView as a scanning region for my readerView. Rather than do :

readerView.scanCrop = scanView.frame;

我们应该这样做,首先规范每个参数:

We should do this, normalizing every arguments first :

CGFloat x,y,width,height;  
x = scanView.frame.origin.x / readerView.bounds.size.width;
y = scanView.frame.origin.y / readerView.bounds.size.height;
width = scanView.frame.size.width / readerView.bounds.size.width;
height = scanView.frame.size.height / readerView.bounds.size.height;

readerView.scanCrop = CGRectMake(x, y, width, height);

它对我有用。希望有所帮助。

It works for me. Hope that helps.

这篇关于如何使用ZBar阅读器的scanCrop属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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