/// <summary> /// Parse QueryString that define the QR code properties /// </summary> /// <param name="request">HttpRequest containing HTTP GET data</param> /// <returns>A QR code descriptor object</returns> public static CodeDescriptor Init(HttpRequest request) { var cp = new CodeDescriptor(); // Error correction level if (!Enum.TryParse(request.QueryString["e"], out cp.Ecl)) { cp.Ecl = ErrorCorrectionLevel.L; } // Code content to encode cp.Content = request.QueryString["t"]; // Size of the quiet zone if (!Enum.TryParse(request.QueryString["q"], out cp.QuietZones)) { cp.QuietZones = QuietZoneModules.Two; } // Module size if (!int.TryParse(request.QueryString["s"], out cp.ModuleSize)) { cp.ModuleSize = 12; } return(cp); }
public void ProcessRequest(HttpContext context) { // Retrieve the parameters from the QueryString var codeParams = CodeDescriptor.Init(context.Request); // Encode the content if (codeParams == null || !codeParams.TryEncode()) { context.Response.StatusCode = (int)HttpStatusCode.BadRequest; return; } // Render the QR code as an image using (var ms = new MemoryStream()) { codeParams.Render(ms); context.Response.ContentType = codeParams.ContentType; context.Response.OutputStream.Write(ms.GetBuffer(), 0, (int)ms.Length); } }
/// <summary> /// Parse QueryString that define the QR code properties /// </summary> /// <param name="request">HttpRequest containing HTTP GET data</param> /// <returns>A QR code descriptor object</returns> public static CodeDescriptor Init(HttpRequest request) { var cp = new CodeDescriptor(); // Error correction level if (!Enum.TryParse(request.QueryString["e"], out cp.Ecl)) cp.Ecl = ErrorCorrectionLevel.L; // Code content to encode cp.Content = request.QueryString["t"]; // Size of the quiet zone if (!Enum.TryParse(request.QueryString["q"], out cp.QuietZones)) cp.QuietZones = QuietZoneModules.Two; // Module size if (!int.TryParse(request.QueryString["s"], out cp.ModuleSize)) cp.ModuleSize = 12; return cp; }