user831098
user831098

Reputation: 1823

Generate QR Code - initQRCodeForInputByteSize cannot find proper rs block info (input data too big?)

I have the error:

initQRCodeForInputByteSize cannot find proper rs block info (input data too big?)

when I generate the QR code.

Here is the code:

NSData *stringData = [qrString dataUsingEncoding: NSISOLatin1StringEncoding];
CIFilter *qrFilter = [CIFilter filterWithName:@"CIQRCodeGenerator"];
[qrFilter setValue:stringData forKey:@"inputMessage"];
[qrFilter setValue:@"L" forKey:@"inputCorrectionLevel"];  

CIImage *qrCodeImage = qrFilter.outputImage;

Does anyone know how to solve the problem?

Upvotes: 1

Views: 881

Answers (2)

PakitoV
PakitoV

Reputation: 2498

The error is giving you a big hint, the data you are trying to transform into a QR is too big.

QR Capacity

  • Numeric Only Max. 7089 characters
  • Alphanumeric Max. 4296 characters
  • Binary (8 Bits) Max. 2953 characters

As obvious as it sounds the solution is to reduce the amount of data, if you cannot renounce to this amount of data you could just use the QR to encode an URL pointing to the bulk of the data hosted somewhere else.

Upvotes: 1

Brandon Stillitano
Brandon Stillitano

Reputation: 1736

When posting on StackOverflow you should include a full code sample and not just the first five lines from the tutorial you're using. This allows, as developers to get some context as to what you've tried and the source of your problem.

  1. Make sure that you're importing the CoreImage framework to your project
  2. Try running the default code included in the tutorial you're using like below

Code pulled from here

NSString *info = @"http://codeafterhours.wordpress.com";

// Generation of QR code image
NSData *qrCodeData = [info dataUsingEncoding:NSISOLatin1StringEncoding]; // recommended encoding
CIFilter *qrCodeFilter = [CIFilter filterWithName:@"CIQRCodeGenerator"];
[qrCodeFilter setValue:qrCodeData forKey:@"inputMessage"];
[qrCodeFilter setValue:@"M" forKey:@"inputCorrectionLevel"]; //default of L,M,Q & H modes

CIImage *qrCodeImage = qrCodeFilter.outputImage;

CGRect imageSize = CGRectIntegral(qrCodeImage.extent); // generated image size
CGSize outputSize = CGSizeMake(240.0, 240.0); // required image size
CIImage *imageByTransform = [qrCodeImage imageByApplyingTransform:CGAffineTransformMakeScale(outputSize.width/CGRectGetWidth(imageSize), outputSize.height/CGRectGetHeight(imageSize))];

UIImage *qrCodeImageByTransform = [UIImage imageWithCIImage:imageByTransform];
self.imgViewQRCode.image = qrCodeImageByTransform;

If this works it would indicate to me that you are declaring your 'qrString' variable incorrectly. If you could share that with us it would help.

Upvotes: 0

Related Questions