iOS Question How to recognize QR code in image

Discussion in 'iOS Questions' started by shirlun, Oct 13, 2018.

  1. shirlun

    shirlun Member Licensed User

  2. Erel

    Erel Administrator Staff Member Licensed User

    Yes.

    1. Add this code:
    Code:
    #if OBJC
    @import CoreImage;
    - (NSArray*) detectQR: (UIImage*)img {
    int exifOrientation;
    switch (img.imageOrientation) {
      case UIImageOrientationUp:
      exifOrientation = 1;
      break;
      case UIImageOrientationDown:
      exifOrientation = 3;
      break;
      case UIImageOrientationLeft:
      exifOrientation = 8;
      break;
      case UIImageOrientationRight:
      exifOrientation = 6;
      break;
      case UIImageOrientationUpMirrored:
      exifOrientation = 2;
      break;
      case UIImageOrientationDownMirrored:
      exifOrientation = 4;
      break;
      case UIImageOrientationLeftMirrored:
      exifOrientation = 5;
      break;
      case UIImageOrientationRightMirrored:
      exifOrientation = 7;
      break;
      default:
      break;
    }

    NSDictionary *detectorOptions = @{ CIDetectorAccuracy : CIDetectorAccuracyHigh };
    CIDetector *detector = [CIDetector detectorOfType:CIDetectorTypeQRCode  context:nil options:detectorOptions];

    NSArray *features = [detector featuresInImage:[CIImage imageWithCGImage:img.CGImage]
      options:@{CIDetectorImageOrientation:[NSNumber numberWithInt:exifOrientation]}];
       return features;
    }
    #end if
    2. Use it like this:
    Code:
    Dim no As NativeObject = Me
    Dim res As List = no.RunMethod("detectQR:"Array(LoadBitmap(File.DirAssets, "qr.png")))
    For Each qr As NativeObject In res
       
    Log(qr.RunMethod("messageString"Null).AsString)
    Next
     
  3. shirlun

    shirlun Member Licensed User

    Perfect, thank you
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice