Two-dimensional code generation based on Gma.QrCodeNet.Encoding

Source: Internet
Author: User
Tags httpcontext

Reference: http://www.cnblogs.com/vmyspace/archive/2012/04/05/2433233.html

Today, project needs, references wrote a QR code generation background based on Gma.QrCodeNet.Encoding

Front desk HTML directly request address, fixed image aspect can be used.

Using System;
Using System.Collections.Generic;
Using System.Web;
Using Gma.QrCodeNet.Encoding;
Using System.IO;
Using System.Text;
Using System.Drawing;
Using System.Drawing.Drawing2D;


Namespace Testweb.erweima_test
{
<summary>
Summary description of Handler2
</summary>
public class Handler2:ihttphandler
{

public void ProcessRequest (HttpContext context)
{
if (!string. IsNullOrEmpty (context. request["Qrdata"]. ToString ()))
{
CREATEQR (context);
}

}

public void Createqr (HttpContext context)
{
Qrencoder Qrencoder = new Qrencoder (ErrorCorrectionLevel.H);
QRCode QRCode = new QRCode ();
String data = "0150204whxtl/?type=invate";
String data = context. request["Qrdata"]. ToString ();
String data = context. request.querystring["Qrdata"]. ToString ();
System.Drawing.Bitmap image;
QRCode = Qrencoder.encode (data);
Image = New Bitmap (QrCode.Matrix.Width * 5, QrCode.Matrix.Height * 5);
Image. Setresolution (180f, 180f);
Graphics gdiobj = graphics.fromimage (image);
gdiobj.compositingquality = compositingquality.highquality;
Gdiobj. SmoothingMode = smoothingmode.highquality;
Gdiobj. Interpolationmode = Interpolationmode.highqualitybicubic;
Gdiobj. Pixeloffsetmode = pixeloffsetmode.highquality;

for (Int32 i = 0; i < qrCode.Matrix.Height; i++)
{
for (Int32 j = 0; J < QrCode.Matrix.Width; J + +)
{
if (Qrcode.matrix.internalarray[i, J])
{
Gdiobj. FillRectangle (New SolidBrush (color.black), I * 5, J * 5, 5, 5);
}
}
}

System.Drawing.Imaging.EncoderParameters EP = new System.Drawing.Imaging.EncoderParameters (1);
Ep. Param[0] = new System.Drawing.Imaging.EncoderParameter (System.Drawing.Imaging.Encoder.Quality, 800L);

System.IO.MemoryStream mstream = new System.IO.MemoryStream ();
Image. Save (Mstream, System.Drawing.Imaging.ImageFormat.Png);
Image. Save (Mstream, NULL, EP);
Context. Response.clearcontent ();
Context. Response.ContentType = "Image/png";
Context. Response.BinaryWrite (Mstream.toarray ());


}

public bool IsReusable
{
Get
{
return false;
}
}
}
}

Two-dimensional code generation based on Gma.QrCodeNet.Encoding

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.