iOS Code Snippet Detect QR code from an image

Hello team,

Here is the iOS version of QR detection:
B4X:
Dim no As NativeObject = Me
Dim res As List = no.RunMethod("detectQR:", Array(LoadBitmap(xui.DefaultFolder, "image.jpeg")))
           
For Each feature As NativeObject In res
    Log(feature.GetField("messageString").AsString)
Next

#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 *faceDetector = [CIDetector detectorOfType:CIDetectorTypeQRCode  context:nil options:detectorOptions];

NSArray *features = [faceDetector featuresInImage:[CIImage imageWithCGImage:img.CGImage]
  options:@{CIDetectorImageOrientation:[NSNumber numberWithInt:exifOrientation]}];

  return features;

}
#end if

Thank you Erel for your help.
 

cxbs

Member
Licensed User
This code cannot read the barcode in the simulator. It can only be used on the real machine
 

yiankos1

Active Member
Licensed User
This code cannot read the barcode in the simulator. It can only be used on the real machine
Hello,
Thank you for trying code snippet. As title mentions, it scans QR code from a bitmap. I don't know if it can scan barcode. It's nothing to do about the simulator.
 

cxbs

Member
Licensed User
Hello,
Thank you for trying code snippet. As title mentions, it scans QR code from a bitmap. I don't know if it can scan barcode. It's nothing to do about the simulator.
Hello!
After real machine test, it can read multiple two-dimensional codes in the picture, but it does not support one-dimensional bar code.
The above English is from translation software
 
Top