Note on calling camera devices in iOS systems to realize QR code scanning (3/3)

Source: Internet
Author: User

Do you remember the class object of the output data we used earlier? Avcapturemetadataoutput, that's it! If we need to implement the current mainstream app scanning QR code function, that is, only when the QR code into the box in the center of the view to scan the recognition function, the purpose is mainly to improve the user experience, need to use a property of this class: Rectofinterest, This property is a cgrect struct type. But it's a little different from the cgrect we usually use. The following intercepts the description of this attribute in the official website document:

/*!

@property rectofinterest

@abstract Specifies a rectangle of interest for limiting the search area for visual metadata.

@discussion the value of this property was a cgrect that determines the receiver's rectangle of interest for each frame  of video.

The rectangle's origin is top left and are relative to the coordinate space of the device providing the metadata. Specifying

A rectofinterest may improve detection performance for certain types of metadata. The default value of the

Value CGRectMake (0, 0, 1, 1). Metadata objects whose bounds do no intersect with the rectofinterest won't be returned.

*/

@property (nonatomic) cgrect rectofinterest Ns_available_ios (7_0);

From the above properties and the current network of resources to understand that the role of this property is roughly set to effectively scan the area, specific to CGRectMake (X,y,width,height) The properties of each item, you can explain:

1.x and y indicate the upper-left position of the active scan area we will set to the top and left values of the preview layer we have set, and the width and height are the height and width of the active sweep area, respectively. In fact, you can already feel the special nature of this property here? is to swap positions of X and y in the cgrect structure we normally use, width and height.

2. However, the value of X,y,width,height is any value between 0~1, which translates the original absolute value to the scale of the occupied area.

According to this explanation, in the actual code to test, found that this is not the case at all, but after repeated testing, finally found the secret, which may be Apple's design and official website description of the bug in the document, misleading the vast number of developers.

The correct understanding should be this:

Remember two points to be able to control all this perfectly, 1. The upper-left corner of the active scan area (which is consistent with the iOS origin in the upper-left corner); 2. The origin of the preview layer is in the upper right corner (not sure if it is not the apple design mistake, if not, it is only a wonderful design). That is, you need to correct the above understanding and most of the current network understanding, thex value represents the distance from the top of the preview layer in the upper left corner of the active scan area, and the Y value code effectively scans the upper-left corner of the area from the right side of the preview layer .

I do not know whether you are the apple of this involved in a terrible toss, anyway, I was a monkey! All right, I'll talk to you today, and we will continue to update other content, thank you very much!

Reprint please specify the source! Respect the original!

Note on calling camera devices in iOS systems to realize QR code scanning (3/3)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.