From 4664b5b8885562cb2a14c5dcb3df4fc07bf960ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cbill=2Echan=E2=80=9D?= <“bill.chan@ums.ag”> Date: Thu, 16 Apr 2015 10:31:17 +0200 Subject: [PATCH 1/3] New function for getting image size and QR code version. + (UIImage *)mdQRCodeForString:(NSString *)qrString size:(CGFloat)imageSize fillColor:(UIColor *)fillColor :(int *)width :(int *)version; --- QRCode/QR/UIImage+MDQRCode.h | 2 +- QRCode/QR/UIImage+MDQRCode.m | 48 ++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/QRCode/QR/UIImage+MDQRCode.h b/QRCode/QR/UIImage+MDQRCode.h index 052b4e3..485b0d7 100644 --- a/QRCode/QR/UIImage+MDQRCode.h +++ b/QRCode/QR/UIImage+MDQRCode.h @@ -33,6 +33,6 @@ */ + (UIImage *)mdQRCodeForString:(NSString *)qrString size:(CGFloat)size; + (UIImage *)mdQRCodeForString:(NSString *)qrString size:(CGFloat)size fillColor:(UIColor *)fillColor; - ++ (UIImage *)mdQRCodeForString:(NSString *)qrString size:(CGFloat)imageSize fillColor:(UIColor *)fillColor :(int *)width :(int *)version; @end diff --git a/QRCode/QR/UIImage+MDQRCode.m b/QRCode/QR/UIImage+MDQRCode.m index 01d9dcf..7f5a102 100644 --- a/QRCode/QR/UIImage+MDQRCode.m +++ b/QRCode/QR/UIImage+MDQRCode.m @@ -106,4 +106,52 @@ + (UIImage *)mdQRCodeForString:(NSString *)qrString size:(CGFloat)imageSize fill return qrImage; } ++ (UIImage *)mdQRCodeForString:(NSString *)qrString size:(CGFloat)imageSize fillColor:(UIColor *)fillColor :(int *)width :(int *)version +{ + if (0 == [qrString length]) { + return nil; + } + + // generate QR + QRcode *code = QRcode_encodeString([qrString UTF8String], 0, QR_ECLEVEL_L, QR_MODE_8, 1); + if (!code) { + return nil; + } + + CGFloat size = imageSize * [[UIScreen mainScreen] scale]; + + *width = code->width; + *version = code->version; + + if (code->width > size) { + printf("Image size is less than qr code size (%d)\n", code->width); + return nil; + } + + // create context + CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); + + // The constants for specifying the alpha channel information are declared with the CGImageAlphaInfo type but can be passed to this parameter safely. + + CGContextRef ctx = CGBitmapContextCreate(0, size, size, 8, size * 4, colorSpace, (CGBitmapInfo)kCGImageAlphaPremultipliedLast); + + CGAffineTransform translateTransform = CGAffineTransformMakeTranslation(0, -size); + CGAffineTransform scaleTransform = CGAffineTransformMakeScale(1, -1); + CGContextConcatCTM(ctx, CGAffineTransformConcat(translateTransform, scaleTransform)); + + // draw QR on this context + [self mdDrawQRCode:code context:ctx size:size fillColor:fillColor]; + + // get image + CGImageRef qrCGImage = CGBitmapContextCreateImage(ctx); + UIImage * qrImage = [UIImage imageWithCGImage:qrCGImage]; + + // free memory + CGContextRelease(ctx); + CGImageRelease(qrCGImage); + CGColorSpaceRelease(colorSpace); + QRcode_free(code); + return qrImage; +} + @end From da2420602d8e8bb41e002be6bdd134bc573026e1 Mon Sep 17 00:00:00 2001 From: Alex Zarochintsev Date: Wed, 13 May 2015 15:26:15 +0300 Subject: [PATCH 2/3] Create .podspec file --- QRCodeEncoder.podspec | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 QRCodeEncoder.podspec diff --git a/QRCodeEncoder.podspec b/QRCodeEncoder.podspec new file mode 100644 index 0000000..76ca0d4 --- /dev/null +++ b/QRCodeEncoder.podspec @@ -0,0 +1,15 @@ +Pod::Spec.new do |s| + s.name = 'QRCodeEncoder' + s.version = '1.0' + s.platform = :ios, '7.0' + s.license = { :type => 'MIT', :file => 'LICENSE' } + s.summary = 'QRCode Encoder For Your iOS app.' + s.homepage = 'https://github.com/Notan/ios-qr-code-encoder' + s.authors = { 'Alex Zarochintsev' => 'alex.zarochintsev@icloud.com' } + s.source = { :git => 'https://github.com/Notan/ios-qr-code-encoder', :tag => "1.0" } + + s.source_files = 'QRCode/QR/**/*.{h,m,c}' + + s.framework = 'Foundation', 'UIKit' + s.requires_arc = true +end \ No newline at end of file From 15614c213e3c5887ea702bb22deafddfe172206e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cbill=2Echan=E2=80=9D?= <“bill.chan@ums.ag”> Date: Fri, 5 Jun 2015 12:16:51 +0200 Subject: [PATCH 3/3] allow nil for parameter returning --- QRCode/QR/UIImage+MDQRCode.m | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/QRCode/QR/UIImage+MDQRCode.m b/QRCode/QR/UIImage+MDQRCode.m index 7f5a102..e77c444 100644 --- a/QRCode/QR/UIImage+MDQRCode.m +++ b/QRCode/QR/UIImage+MDQRCode.m @@ -120,8 +120,14 @@ + (UIImage *)mdQRCodeForString:(NSString *)qrString size:(CGFloat)imageSize fill CGFloat size = imageSize * [[UIScreen mainScreen] scale]; + if(width) + { *width = code->width; + } + if(version) + { *version = code->version; + } if (code->width > size) { printf("Image size is less than qr code size (%d)\n", code->width);