Permalink
Browse files

Adding a scale factor for the QR images

The QR images are can now be created with a scale factor. So if you need
an image to cover the whole screen on an iPhone for example, increasing
the scale factor will provide a larger image.
  • Loading branch information...
Gabriel Gabriel Radu
Gabriel authored and Gabriel Radu committed Apr 19, 2011
1 parent 1b6ede0 commit 311dd81a25c09d8ccefbb77de1e8f6572e7aeba8
Showing with 11 additions and 10 deletions.
  1. +9 −8 src/Classes/QREncoder.m
  2. +2 −2 src/Classes/QREncoder/QREncoder.h
View
@@ -368,13 +368,14 @@ - (void)dealloc {
////////////////////////////////////////////////////////////////////////////////////////////////////
-+ (UIImage *)imageForMatrix:(QRMatrix *)matrix {
- int width = matrix.width;
- int height = matrix.height;
++ (UIImage *)imageForMatrix:(QRMatrix *)matrix scaleFactor:(int)scaleFactor {
+
+ int width = matrix.width * scaleFactor;
+ int height = matrix.height * scaleFactor;
unsigned char *bytes = (unsigned char *)malloc(width * height * 4);
for(int y = 0; y < height; y++) {
for(int x = 0; x < width; x++) {
- BOOL bit = [matrix getX:x y:y];
+ BOOL bit = [matrix getX:x/scaleFactor y:y/scaleFactor];
unsigned char intensity = bit ? 0 : 255;
for(int i = 0; i < 3; i++) {
bytes[y * width * 4 + x * 4 + i] = intensity;
@@ -400,13 +401,13 @@ + (UIImage *)imageForMatrix:(QRMatrix *)matrix {
////////////////////////////////////////////////////////////////////////////////////////////////////
-+ (UIImage *)encode:(NSString *)str {
- return [QREncoder encode:str size:4 correctionLevel:QRCorrectionLevelHigh];
++ (UIImage *)encode:(NSString *)str scaleFactor:(int)scaleFactor {
+ return [QREncoder encode:str size:4 correctionLevel:QRCorrectionLevelHigh scaleFactor:scaleFactor];
}
////////////////////////////////////////////////////////////////////////////////////////////////////
-+ (UIImage *)encode:(NSString *)str size:(int)size correctionLevel:(QRCorrectionLevel)level {
++ (UIImage *)encode:(NSString *)str size:(int)size correctionLevel:(QRCorrectionLevel)level scaleFactor:(int)scaleFactor {
QREncoder *encoders[8];
for(int i = 0; i < 8; i++) {
encoders[i] = [[QREncoder alloc] initWithStr:str size:size correctionLevel:level pattern:i];
@@ -427,7 +428,7 @@ + (UIImage *)encode:(NSString *)str size:(int)size correctionLevel:(QRCorrection
UIImage *image;
if (encoder != nil) {
- image = [QREncoder imageForMatrix:encoder->_matrix];
+ image = [QREncoder imageForMatrix:encoder->_matrix scaleFactor:scaleFactor];
} else {
image = nil;
}
@@ -32,7 +32,7 @@
QRMatrix* _matrix;
}
-+ (UIImage *)encode:(NSString *)str;
-+ (UIImage *)encode:(NSString *)str size:(int)size correctionLevel:(QRCorrectionLevel)level;
++ (UIImage *)encode:(NSString *)str scaleFactor:(int)scaleFactor;
++ (UIImage *)encode:(NSString *)str size:(int)size correctionLevel:(QRCorrectionLevel)level scaleFactor:(int)scaleFactor;
@end

0 comments on commit 311dd81

Please sign in to comment.