OMGPOP OMGPOP - 2 years ago 391
iOS Question

iOS 7 Core Image QR Code generation too blur

here's my code for generating QRCode image

+ (UIImage *)generateQRCodeWithString:(NSString *)string {
NSData *stringData = [string dataUsingEncoding:NSUTF8StringEncoding];
CIFilter *filter = [CIFilter filterWithName:@"CIQRCodeGenerator"];
[filter setValue:stringData forKey:@"inputMessage"];
[filter setValue:@"M" forKey:@"inputCorrectionLevel"];
return [UIImage imageWithCIImage:filter.outputImage];

The result is too blur. Is it possible to set the size of the generated qr code?

Answer Source

I was about to start bounty on this question but i found the answer.

What you need is a scale filter. To achieve this with CoreImage, you need to do something like this:

CIImage *input = [CIImage imageWithCGImage: ImageView.Image.CGImage]; // input image is 100 X 100
CGAffineTransform transform = CGAffineTransformMakeScale(5.0f, 5.0f); // Scale by 5 times along both dimensions
CIImage *output = [input imageByApplyingTransform: transform];
// output image is now 500 X 500


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download