This article describes a two-dimensional code that asp.net (C #) uses QRCode to generate a logo or image in the center of a picture. Share to everyone for your reference, specific as follows:
<%@ WebHandler language= "C #" class= "Getqrcode"%> using System;
Using System.Web;
Using ThoughtWorks.QRCode.Codec;
Using ThoughtWorks.QRCode.Codec.Data;
Using ThoughtWorks.QRCode.Codec.Util;
Using System.IO;
Using System.Text;
Using System.Drawing;
Using System.Drawing.Drawing2D; public class Getqrcode:ihttphandler {public void ProcessRequest (HttpContext context) {String data = context.
request["Codetext"]; if (!string.
IsNullOrEmpty (data)) {Qrcodeencoder Qrcodeencoder = new Qrcodeencoder (); Qrcodeencoder.qrcodeencodemode = Qrcodeencoder.encode_mode.
BYTE;
Qrcodeencoder.qrcodescale = 4;
Qrcodeencoder.qrcodeversion = 8; Qrcodeencoder.qrcodeerrorcorrect = qrcodeencoder.error_correction.
M
System.Drawing.Image Image = qrcodeencoder.encode (data);
System.IO.MemoryStream mstream = new System.IO.MemoryStream (); Image.
Save (Mstream, System.Drawing.Imaging.ImageFormat.Png); System.IO.MemoryStream MStream1 = new System. Io.
MemoryStream (); Combinimage (image, context. Server.MapPath ("~/images/201292891051540.jpg")).
Save (MStream1, System.Drawing.Imaging.ImageFormat.Png); Context.
Response.clearcontent (); Context.
Response.ContentType = "Image/png"; Context.
Response.BinaryWrite (Mstream1.toarray ()); Image.
Dispose ();
Mstream.dispose ();
Mstream1.dispose (); } context.
Response.Flush (); Context.
Response.End (); ///<summary>///Call this function to merge the two pictures, similar albums, have a///background, the middle of their target picture///</summary>///<param name= "img Back "> Paste source Picture </param>///<param name=" destimg "> pasted target picture </param> public static image Combinimage (I Mage Imgback, String destimg) {Image img = image.fromfile (destimg); Photo Picture if (IMG). Height!= 65 | | Img.
Width!=) {img = Kiresizeimage (IMG, 65, 65, 0);
} Graphics g = Graphics.fromimage (Imgback); G.drawimage (imgback, 0, 0, imgback.width, imgback.height); G.drawimage (imgBack, 0, 0, picture frame width, frame height); G.fillrectangle (System.Drawing.Brushes.White, IMGBACK.WIDTH/2-img. WIDTH/2-1, IMGBACK.WIDTH/2-img.
WIDTH/2-1,1,1)//photo around a black border//g.drawimage (img, photo and frame left margin, photo and frame of the top margin, photo width, photo high); G.drawimage (IMG, IMGBACK.WIDTH/2-img). WIDTH/2, Imgback.width/2-img. WIDTH/2, IMG. Width, IMG.
Height); Gc.
Collect ();
return imgback; ///<summary>///Resize pictures///</summary>///<param name= "BMP" > Original bitmap</param>///& Lt;param name= "NEWW" > New width </param>///<param name= "NEWH" > New heights </param>///<param "Mode" & gt; reserved, temporarily unused </param>///<returns> processed pictures </returns> public static image kiresizeimage (image bmp, int
NEWW, int newh, int Mode) {try {Image b = new Bitmap (NEWW, NEWH);
Graphics g = graphics.fromimage (b);
The quality G.interpolationmode = Interpolationmode.highqualitybicubic of interpolation algorithm; G.drawimage (BMP, New Rectangle (0, 0, nEwW, NEWH), new Rectangle (0, 0, BMP. Width, BMP.
Height), GraphicsUnit.Pixel);
G.dispose ();
return b;
catch {return null;
} public bool IsReusable {get {false;
}
}
}
The effect is as shown in the following illustration:
PS: This site also provides a very powerful online two-dimensional code generation tool to achieve text, phone numbers, text messages, mail, URLs and other two-dimensional code generation and logo icon add function:
Online generation of two-dimensional code tool (enhanced version):
Http://tools.jb51.net/transcoding/jb51qrcode
More interested readers of asp.net related content can view the site topics: "asp.net operation JSON tips summary", "asp.net string operation tips Summary", "ASP.net Operation XML Skills summary", "asp.net file Operation skills Summary", " asp.net Ajax Skills Summary topic and the "ASP.net cache operation skills Summary."
I hope this article will help you to ASP.net program design.