Create PNG image with QRCode for iPhone

I use zxing to decode QRCodes. I also now got the encoder working and can create a QRCode that contains encoded data.

I ask if anyone knows how to convert QRCOde data to a png image.

+6
source share
5 answers

If your application has online access, you can use something like http://www.tag.cx/qr-codes/

Many users are looking for a way to code QR codes and other codes programmatically on the iPhone. These features were not ported from Android to iPhone, but as described in this Zxing thread: https://groups.google.com/group/zxing/browse_thread/thread/7325ed13cc49122c/aba6f4545c5c3583?lnk=gst&q=encode+to+png + iphone # aba6f4545c5c3583

Please see this question for further discussion: Create a 2D barcode (e.g. QR code, data matrix, PDF417) on iPhone and Android

You can use Phonegap to encode a QR barcode using the plugin here . Follow the instructions and you must be successful.

Javascript is simple, taken directly from https://github.com/phonegap/phonegap-plugins/

window.plugins.barcodeScanner.encode(BarcodeScanner.Encode.TEXT_TYPE, "http://www.nytimes.com", function(success) { alert("encode success: " + success); }, function(fail) { alert("encoding failed: " + fail); }, {yesString: "Install"} ); 
+3
source

The psytec encoder (http://groups.google.com/group/zxing/msg/27e421daeb510d0f) works well. I use it in production. It should be relatively nice to use something like libpng to go from the bit array it creates to png. On devices, I scan the array of bits it produces and draw directly in CG contexts.

0
source

If you are using telephone service and need offline support, maybe jquery qrcode might help.

0
source

Download the sample code for the Generator QR code from this Github link, simpler and simpler. Add the resource files that were used in this sample project to your project.

If you just want to show the QR code generated in UIImageview , you can directly use the code in the sample project

or

If you need a png file with a QR code, you can get NSData from a UIImageview image and convert the NSData file to png and use it.

0
source

Edited There are similar questions in this post, I am associated with this answer.

I used this simple code to encode QRCode in one of my projects. You can use:

 // // QRCodeGeneratorViewController.h // // // Created by Jhoney Lopes on 28/09/14. // Copyright (c) 2014 Jhoney Lopes. All rights reserved. // #import <UIKit/UIKit.h> @interface QRCodeGeneratorViewController : UIViewController @end 

Executing .m

 // // QRCodeGeneratorViewController.m // // // Created by Jhoney Lopes on 28/09/14. // Copyright (c) 2014 Jhoney Lopes. All rights reserved. // #import "QRCodeGeneratorViewController.h" @interface QRCodeGeneratorViewController () @property (strong, nonatomic) IBOutlet UIImageView *qrImageView; @end @implementation QRCodeGeneratorViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self generateTheQRCodeImageFromDataBaseInfo:@"TEXT-WHAT-YOU-WANT-TO-CONVERT-IN-QRCODE"]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } #pragma mark - QR Code Generator - (CIImage *)createQRForString:(NSString *)qrString { // Need to convert the string to a UTF-8 encoded NSData object NSData *stringData = [qrString dataUsingEncoding:NSUTF8StringEncoding]; // Create the filter CIFilter *qrFilter = [CIFilter filterWithName:@"CIQRCodeGenerator"]; // Set the message content and error-correction level [qrFilter setValue:stringData forKey:@"inputMessage"]; [qrFilter setValue:@"H" forKey:@"inputCorrectionLevel"]; // Send the image back return qrFilter.outputImage; } - (UIImage *)createNonInterpolatedUIImageFromCIImage:(CIImage *)image withScale:(CGFloat)scale { // Render the CIImage into a CGImage CGImageRef cgImage = [[CIContext contextWithOptions:nil] createCGImage:image fromRect:image.extent]; // Now we'll rescale using CoreGraphics UIGraphicsBeginImageContext(CGSizeMake(image.extent.size.width * scale, image.extent.size.width * scale)); CGContextRef context = UIGraphicsGetCurrentContext(); // We don't want to interpolate (since we've got a pixel-correct image) CGContextSetInterpolationQuality(context, kCGInterpolationNone); CGContextDrawImage(context, CGContextGetClipBoundingBox(context), cgImage); // Get the image out UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext(); // Tidy up UIGraphicsEndImageContext(); CGImageRelease(cgImage); return scaledImage; } - (void)generateTheQRCodeImageFromDataBaseInfo:(NSString *)jsonString { // Get the string NSString *stringToEncode = jsonString; // Generate the image CIImage *qrCode = [self createQRForString:stringToEncode]; // Convert to an UIImage UIImage *qrCodeImg = [self createNonInterpolatedUIImageFromCIImage:qrCode withScale:2*[[UIScreen mainScreen] scale]]; // And push the image on to the screen self.qrImageView.image = qrCodeImg; } 
0
source

Source: https://habr.com/ru/post/888751/


All Articles