Skip to content

Instantly share code, notes, and snippets.

@mikebluestein
Created July 27, 2014 14:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mikebluestein/b784ab08889d83fb0a43 to your computer and use it in GitHub Desktop.
Save mikebluestein/b784ab08889d83fb0a43 to your computer and use it in GitHub Desktop.
Create QR code
var imageView = new UIImageView ();
imageView.Frame = UIScreen.MainScreen.Bounds;
imageView.ContentMode = UIViewContentMode.ScaleAspectFit;
var qrCode = new CIQRCodeGenerator {
Message = NSData.FromString ("test"),
CorrectionLevel = "Q"
}.OutputImage;
UIGraphics.BeginImageContext (new SizeF (qrCode.Extent.Width * 8, qrCode.Extent.Height * 8));
var cgCtx = UIGraphics.GetCurrentContext ();
var ciCtx = CIContext.FromOptions (null);
cgCtx.InterpolationQuality = CGInterpolationQuality.None;
cgCtx.DrawImage (cgCtx.GetClipBoundingBox (), ciCtx.CreateCGImage (qrCode, qrCode.Extent));
using (var image = UIGraphics.GetImageFromCurrentImageContext ()) {
imageView.Image = image;
}
UIGraphics.EndImageContext ();
View.AddSubview (imageView);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment