Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

version and size info for QR code. #5

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion QRCode/QR/UIImage+MDQRCode.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
54 changes: 54 additions & 0 deletions QRCode/QR/UIImage+MDQRCode.m
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,58 @@ + (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];

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);
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
15 changes: 15 additions & 0 deletions QRCodeEncoder.podspec
Original file line number Diff line number Diff line change
@@ -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' => '[email protected]' }
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