Example #1
0
 /// <summary>
 /// Try to encode content
 /// </summary>
 /// <param name="content">The content.</param>
 /// <param name="qrCode">The qr code.</param>
 /// <returns>False if input content is empty, null or too large.</returns>
 /// <remarks></remarks>
 public bool TryEncode(string content, out QrCode qrCode)
 {
     try
     {
         qrCode = Encode(content);
         return(true);
     }
     catch (InputOutOfBoundaryException)
     {
         qrCode = new QrCode();
         return(false);
     }
 }
Example #2
0
 /// <summary>
 /// Try to encode content
 /// </summary>
 /// <param name="content">The content.</param>
 /// <param name="qrCode">The qr code.</param>
 /// <returns>False if input content is empty, null or too large.</returns>
 /// <remarks></remarks>
 public bool TryEncode(string content, out QrCode qrCode)
 {
     try
     {
         qrCode = Encode(content);
         return true;
     }
     catch (InputOutOfBoundaryException)
     {
         qrCode = new QrCode();
         return false;
     }
 }
Example #3
0
        /// <summary>
        /// Enables processing of HTTP Web requests by a custom HttpHandler that implements the <see cref="T:System.Web.IHttpHandler"/> interface.
        /// </summary>
        /// <param name="context">An <see cref="T:System.Web.HttpContext"/> object that provides references to the intrinsic server objects (for example, Request, Response, Session, and Server) used to service HTTP requests.</param>
        /// <remarks></remarks>
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "image/jpeg";

            var text = context.Request.QueryString["Text"];

            QrEncoder qrEncoder = new QrEncoder(ErrorCorrectionLevel.H);

            QrCode.Web.Encoder.QrCode qrCode = qrEncoder.Encode(text);

            GraphicsRenderer renderer = new GraphicsRenderer(new FixedModuleSize(5, QuietZoneModules.Two), Brushes.Black, Brushes.White);

            renderer.WriteToStream(qrCode.Matrix, ImageFormat.Jpeg, context.Response.OutputStream);
        }
Example #4
0
        private void GetQrImage()
        {
            HttpContext.Current.Response.ContentType = "image/jpeg";


            QrEncoder qrEncoder = new QrEncoder(ErrorCorrectionLevel.H);

            QrCode.Web.Encoder.QrCode qrCode = qrEncoder.Encode(this.Text);

            GraphicsRenderer renderer = new GraphicsRenderer(new FixedModuleSize(5, QuietZoneModules.Two), Brushes.Black, Brushes.White);

            renderer.WriteToStream(qrCode.Matrix, ImageFormat.Png, HttpContext.Current.Response.OutputStream);

            //using (FileStream stream = new FileStream(@"c:\temp\HelloWorld.png", FileMode.Create))
            //{
            //    renderer.WriteToStream(qrCode.Matrix, ImageFormat.Png, stream);

            //    img.Save(HttpContext.Current.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
            //}

            //image.Save(context.Response.OutputStream, ImageFormat.Jpeg)
        }