zoukankan      html  css  js  c++  java
  • C#版的二维码生成器

    这里是二维码的介绍http://blog.sina.com.cn/s/blog_4d8333670100t8mr.html

    下面是我用C#作为后台代码做的一个二维码生成器的代码:

    前端:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="main.aspx.cs" Inherits="二维码生成器.main" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="生成二维码" />
        
        </div>
        <p>
            &nbsp;</p>
        <p>
            <asp:Image ID="Image1" runat="server" Height="164px" Width="157px" />
        </p>
        </form>
    </body>
    </html>

    后端:

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Web;
     5 using System.Web.UI;
     6 using System.Web.UI.WebControls;
     7 using System.Drawing;
     8 using ThoughtWorks.QRCode.Codec;
     9 using System.Text;
    10 
    11 namespace 二维码生成器
    12 {
    13     public partial class main : System.Web.UI.Page
    14     {
    15         protected void Page_Load(object sender, EventArgs e)
    16         {
    17 
    18         }
    19 
    20         protected void Button1_Click(object sender, EventArgs e)
    21         {
    22             create_QR(this.TextBox1.Text.Trim());
    23         }
    24         private void create_QR(string nr)
    25         {
    26             Bitmap bt;
    27             string encodeString = nr;
    28             QRCodeEncoder qrcodeencoder = new QRCodeEncoder();
    29             bt = qrcodeencoder.Encode(encodeString,Encoding.UTF8);
    30             string filename = "qr.jpg";
    31             bt.Save(Server.MapPath("~/images/") + filename + ".jpg");
    32             this.Image1.ImageUrl = "~/images/" + filename + ".jpg";
    33         }
    34     }
    35 }

    这里主要用的是C#版的一个二维码生成器的一个dll文件,下载地址是http://codefans.net/dll/down/3031.shtml

    很晚了,不细说了,明天晚上 有空再来细细分析下这些代码和扩展。

    看下效果图:

  • 相关阅读:
    [USACO5.3]校园网Network of Schools
    [USACO13OPEN]照片Photo

    flask的orm框架----------Flask-SQLAlchemy应用
    Flask-session用法
    flask--自定义auth模块
    flask -falsk_script用法
    Flask-SQLAlchemy数据库
    flask--session源码解析
    flask-源码请求源码
  • 原文地址:https://www.cnblogs.com/phoneball/p/4273720.html
Copyright © 2011-2022 走看看