Two-dimensional Code simple demo

Source: Internet
Author: User

Two-dimensional Code simple demo

First, the View

@{Layout = null;} <! DOCTYPE html>

Second, the controller

Using system;using system.collections.generic;using system.linq;using system.web;using System.Web.Mvc;using Common;        Using System.drawing;namespace qrcodedemo.controllers{public class Orcodecontroller:controller {//        GET:/orcode/public actionresult Index () {return View (); } [HttpPost] public actionresult getorimage (string content) {//if (string.            IsNullOrEmpty (content))//{//return content (""); } String timestr = DateTime.Now.ToFileTime ().            ToString ();            Bitmap Bitmap = qrcodeop.qrcodeencoderutil (content);            String fileName = Server.MapPath ("~") + "content\\images\\qrimages\\" + timestr + ". jpg"; Bitmap. Save (FileName);//saving bitmap string imageUrl = "/content/images/qrimages/" + timestr + ". jpg";//Display Picture Retu        RN Content (IMAGEURL); } [HttpPost] public actionresult getorimagecontent (strinG imageName) {string fileUrl = Server.MapPath ("~") + "content\\images\\qrimages\\" + imageName;            Bitmap Bitmap = new Bitmap (FILEURL);            String content = Qrcodeop.qrcodedecoderutil (BITMAP);        return content (content); }
}}

Three or two-dimensional code generation tool class

Using system;using system.collections.generic;using system.linq;using system.text;using System.Threading.Tasks; Using thoughtworks.qrcode.codec;using thoughtworks.qrcode.codec.data;using system.drawing;namespace Common{Public Class Qrcodeop {///<summary>//Generate QR Code///</summary>//<param name= " Qrcodecontent "> What to encode </param>//<returns> return two-dimensional code bitmap </returns> public static Bitmap QRC            Odeencoderutil (String qrcodecontent) {Qrcodeencoder Qrcodeencoder = new Qrcodeencoder ();            qrcodeencoder.qrcodeversion = 0;        Bitmap img = Qrcodeencoder.encode (qrcodecontent, Encoding.UTF8);//Specify UTF-8 encoding, support Chinese return img; }///<summary>//parsing QR code///</summary>//<param name= "bitmap" > QR code to parse Bitmap </param>////<returns> parsed string </returns> public static string Qrcodedecoderutil (Bitmap Bitmap        {Qrcodedecoder decoder = new Qrcodedecoder (); String decodedstring = Decoder.decode (new Qrcodebitmapimage (bitmap), Encoding.UTF8);//Specify UTF-8 encoding, support Chinese return D        ecodedstring; }    }}

Four, the effect

Five, source code download

Aps.net MVC4 generate two-dimensional code simple demo source Download

Category: ASP. NET MVC

Two-dimensional Code simple demo

Related Article

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.