shirlun Active Member Licensed User Longtime User Oct 13, 2018 #1 Hi, In B4a I can recognize QR code in image with the method in this thread: https://www.b4x.com/android/forum/t...onal-qrcode-file-of-image-file.81754/#content Is there a method for B4i ? Thanks.
Hi, In B4a I can recognize QR code in image with the method in this thread: https://www.b4x.com/android/forum/t...onal-qrcode-file-of-image-file.81754/#content Is there a method for B4i ? Thanks.
Erel B4X founder Staff member Licensed User Longtime User Oct 14, 2018 #2 Yes. 1. Add this code: Code: Copy #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: Copy 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 Upvote 0
Yes. 1. Add this code: Code: Copy #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: Copy 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