从图片扫描
有时候我们需要从图片中扫描二维码,或者从相册选择一张图片,代码如下,具体可以看demo。其中feature.messageString就是扫描后的结果。
1
2
3
4
5
6
7
8
9
10
11
12
|
- (void)findQRCodeFromImage:(UIImage *)image
{
CIDetector *detector = [CIDetector detectorOfType:CIDetectorTypeQRCode
context:nil
options:@{CIDetectorAccuracy:CIDetectorAccuracyHigh}];
NSArray *features = [detector featuresInImage:[CIImage imageWithCGImage:image.CGImage]];
if
(features.count >= 1)
{
CIQRCodeFeature *feature = [features firstObject];
}
}
|