[英]How to read a QR from an image in the device
我已經在iOS應用程序中使用過很多次從相機讀取QR code
的方法。 但是這次,我想從已經存儲在設備中的圖像中獲取QR code
,例如在相冊中。 最好的方法是什么?
您可以使用CoreImage實現此目的。 您可以使用CIDetector類檢查CIDetectorType是否為CIDetectorTypeQRCode
類型。 您可以使用此代碼
他們用來從圖像中檢測QRCode的功能是
func performQRCodeDetection(_ image: CIImage) -> (outImage: CIImage?, decode: String) {
var resultImage: CIImage?
var decode = ""
if let detector = detector {
let features = detector.features(in: image)
for feature in features as! [CIQRCodeFeature] {
resultImage = drawHighlightOverlayForPoints(image, topLeft: feature.topLeft, topRight: feature.topRight,
bottomLeft: feature.bottomLeft, bottomRight: feature.bottomRight)
decode = feature.messageString!
}
}
return (resultImage, decode)
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.