如何从iOS中使用UIImagePickerController选取的图像中扫描Qr代码 [英] How to scan Qr code from an image picked with UIImagePickerController in iOS

查看:116
本文介绍了如何从iOS中使用UIImagePickerController选取的图像中扫描Qr代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用相机扫描qr代码而无需使用任何外部库,如ZBAR或ZXING。

I am able to scan qr code with camera without using any external libraries like ZBAR or ZXING.

现在我真正想要的是让用户上传图像从照片库中获取从上传图像中扫描的二维码。

Now what I actually want is to let the user upload an image from photo library and get the qr code scanned from that uploaded image.

我知道如何使用UIImagePickerController(之前使用过)。

I know how to use UIImagePickerController (used it before).

我想问的是,
如何从上传的图像扫描qr代码(不使用相机)

What I want to ask is that, How can I scan qr code from an uploaded image (without using the camera)

你可以建议我可以在我的项目中添加一些代码(.h / .m文件)。

You can suggest some code (.h / .m files) that I can add in my project.

请不要建议任何外部库,如ZBAR或ZXING。

Please don't suggest me any external libraries like ZBAR or ZXING.

推荐答案

我知道你可能已找到解决方案,但如果我的回答可能有助于其他相关问题我回复帖子。

I know you might have found solution for this but i am replying to the post if my answer may help other for relevant question.

这里我将代码发布到ScanQRCode,而不是使用任何库,而是从图库中选取的图像。

Here I am posting my code to ScanQRCode from image picked from gallery without using any Library.

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {



    if let pickedImage = info[UIImagePickerControllerEditedImage] as? UIImage {
                 let detector:CIDetector=CIDetector(ofType: CIDetectorTypeQRCode, context: nil, options: [CIDetectorAccuracy:CIDetectorAccuracyHigh])

    let ciImage:CIImage = CIImage(image:pickedImage)!

    var qrCodeLink = ""

    let features=detector.featuresInImage(ciImage)

    for feature in features as! [CIQRCodeFeature] {

        qrCodeLink += feature.messageString
    }

    print(qrCodeLink)//Your result from QR Code
}

    dismissViewControllerAnimated(true, completion: nil)
}

这篇关于如何从iOS中使用UIImagePickerController选取的图像中扫描Qr代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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