Пример #1
0
        public override void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear (animated);

            this.View.BackgroundColor = UIColor.LightGray;

            txtQR = new UITextView (new RectangleF (20, 100, this.View.Bounds.Width - 40, 100));
            txtQR.Text = "Xamarin rocks!";
            this.View.AddSubview (txtQR);

            btnQR = new UIButton (UIButtonType.RoundedRect);
            btnQR.Frame = new RectangleF (100, 225, this.View.Bounds.Width - 200, 30);
            btnQR.SetTitle ("Create Code", UIControlState.Normal);

            qrImageView = new UIImageView (new RectangleF (20, 275, 100, 100));
            this.View.AddSubview (qrImageView);

            btnQR.TouchDown += (object sender, EventArgs e) => {

                var gen = new CIQRCodeGenerator ()
                {
                    Message = NSData.FromString (txtQR.Text),
                    CorrectionLevel = "M"
                };

                var context = CIContext.FromOptions (null);

                var cgimage = context.CreateCGImage (gen.OutputImage, gen.OutputImage.Extent);
                qrImageView.Image = UIImage.FromImage (cgimage);
            };

            this.View.AddSubview (btnQR);
        }
Пример #2
0
		/// <summary>
		/// Generates a QR code.
		/// </summary>
		/// <returns>An image with the code.</returns>
		CIImage QRCodeGenerator ()
		{
			var qr_code_generator = new CIQRCodeGenerator () 
			{
				Message = NSData.FromString ("http://xamarin.com"),
				CorrectionLevel = "M",
			};

			return qr_code_generator.OutputImage;
		}