Sample code for 30+ languages & platforms
Objective-C Requires Chilkat v11.7.0+

QR Code Quiet Zone, Padding and Rotation

See more QR Code Examples

Demonstrates the space around a QR code and its rotation. The quiet zone is the blank margin a reader needs around the symbol. It is measured in modules, the QR standard requires 4, and QrCode will make it larger but not smaller. Padding is extra space outside the quiet zone, measured in the render units (pixels by default). Rotation turns the whole image by 90, 180 or 270 degrees. A QR code reads the same at any rotation.

Chilkat Objective-C Downloads

Objective-C
#import <CkoJsonObject.h>
#import <CkoFormats.h>

BOOL success = NO;

//  This example requires the Chilkat API to have been previously unlocked.
//  See Global Unlock Sample for sample code.

CkoJsonObject *json = [[CkoJsonObject alloc] init];
[json UpdateString: @"payload.text" value: @"https://www.chilkatsoft.com/"];
[json UpdateInt: @"render.moduleSize" value: [NSNumber numberWithInt: 6]];

//  A quiet zone of 6 modules on every side instead of the standard 4.
[json UpdateInt: @"render.quietZone.left" value: [NSNumber numberWithInt: 6]];
[json UpdateInt: @"render.quietZone.top" value: [NSNumber numberWithInt: 6]];
[json UpdateInt: @"render.quietZone.right" value: [NSNumber numberWithInt: 6]];
[json UpdateInt: @"render.quietZone.bottom" value: [NSNumber numberWithInt: 6]];

//  10 more pixels of background around that.
[json UpdateInt: @"render.padding" value: [NSNumber numberWithInt: 10]];

//  Turn the image a quarter turn clockwise.
[json UpdateInt: @"render.rotation" value: [NSNumber numberWithInt: 90]];

[json UpdateString: @"output.path" value: @"qa_output/qr_margins.png"];
[json UpdateBool: @"output.overwrite" value: YES];
[json UpdateString: @"output.return" value: @"none"];

CkoFormats *fmt = [[CkoFormats alloc] init];
CkoJsonObject *jsonOut = [[CkoJsonObject alloc] init];
success = [fmt QrCode: @"generate" jsonIn: json jsonOut: jsonOut];
if (success == NO) {
    NSLog(@"%@",fmt.LastErrorText);
    return;
}

NSLog(@"%@%d%@",@"module: ",[[jsonOut IntOf: @"measurements[0].pitch"] intValue],@" pixels");
NSLog(@"%@%d%@%d%@%d%@%d%@",@"symbol: ",[[jsonOut IntOf: @"measurements[0].symbolWidth"] intValue],@" x ",[[jsonOut IntOf: @"measurements[0].symbolHeight"] intValue]
    ,@" pixels at (",[[jsonOut IntOf: @"measurements[0].symbolX"] intValue],@",",[[jsonOut IntOf: @"measurements[0].symbolY"] intValue],@")");
NSLog(@"%@%d%@",@"quiet zone: ",[[jsonOut IntOf: @"measurements[0].quietZonePx.left"] intValue],@" pixels");
NSLog(@"%@%d%@",@"padding: ",[[jsonOut IntOf: @"measurements[0].paddingPx"] intValue],@" pixels");
NSLog(@"%@%d",@"rotation: ",[[jsonOut IntOf: @"measurements[0].rotation"] intValue]);
NSLog(@"%@%d%@%d%@",@"image: ",[[jsonOut IntOf: @"measurements[0].canvasWidth"] intValue],@" x ",[[jsonOut IntOf: @"measurements[0].canvasHeight"] intValue],@" pixels");

//  The image, enlarged, with the quiet zone and the padding tinted here to show where they are.
//  In the image itself both are plain white.  A QR code has no finder pattern (the large squares)
//  in its bottom right corner.  After the quarter turn that corner is at the bottom left:

//  image

//  Sample output:

//  module: 6 pixels
//  symbol: 174 x 174 pixels at (46,46)
//  quiet zone: 36 pixels
//  padding: 10 pixels
//  rotation: 90
//  image: 266 x 266 pixels