asp.net (C #) use QRCode to generate a picture center plus logo or image of a two-dimensional code instance _ practical Skills

Source: Internet
Author: User

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.

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.