Created
July 27, 2014 14:49
-
-
Save mikebluestein/b784ab08889d83fb0a43 to your computer and use it in GitHub Desktop.
Create QR code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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