生成二维码,帮助类:

using Gma.QrCodeNet.Encoding;
using Gma.QrCodeNet.Encoding.Windows.Render;
using System;
using System.Collections.Generic;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace Piano.Utility.Common
{
public class QRCodeHelper
{
/// <summary>
/// 获取二维码
/// </summary>
/// <param name="strContent">待编码的字符</param>
/// <param name="ms">输出流</param>
///<returns>True if the encoding succeeded, false if the content is empty or too large to fit in a QR code</returns>
public static bool GetQRCode(string strContent, MemoryStream ms)
{
ErrorCorrectionLevel Ecl = ErrorCorrectionLevel.M; //误差校正水平
string Content = strContent;//待编码内容
QuietZoneModules QuietZones = QuietZoneModules.Two; //空白区域
int ModuleSize = ;//大小
var encoder = new QrEncoder(Ecl);
QrCode qr;
if (encoder.TryEncode(Content, out qr))//对内容进行编码,并保存生成的矩阵
{
var render = new GraphicsRenderer(new FixedModuleSize(ModuleSize, QuietZones));
render.WriteToStream(qr.Matrix, ImageFormat.Png, ms);
}
else
{
return false;
}
return true;
}
}
}

使用方法(此处是MVC5.2.0模式下):

 //二维码生成
public ActionResult getQrCode()
{ // Render the QR code as an image
using (var ms = new MemoryStream())
{
string url = string.Format(ConfigurationManager.AppSettings["WxgzhUrl"], UserValidator.GetInstituteId());
string stringtest = url;
QRCodeHelper.GetQRCode(stringtest, ms);
Response.ContentType = "image/Png";
Response.OutputStream.Write(ms.GetBuffer(), , (int)ms.Length);
Response.End();
} return View();
}

前端调用:

 <img src="/My/getQrCode" alt="" style="width:160px;height:160px;" /><span class="remindmsg">扫一扫查看</span>

asp.net mvc 生成二维码的更多相关文章

  1. .Net MVC生成二维码并前端展示

    简介: 二维码又称二维条码,常见的二维码为QR Code,QR全称Quick Response,是一个近几年来移动设备上超流行的一种编码方式,它比传统的Bar Code条形码能存更多的信息,也能表示更 ...

  2. Asp.Net Core 生成二维码(NuGet使用QRCoder)

    前言 功能:调用web api 接口 1.获取 jpeg 格式的二维码 2.获取中间带有logo 的二维码 3. 下载 jpeg,svg 格式的二维码 需要的NuGet 包: > QRCoder ...

  3. 利用QrCode.Net生成二维码 asp.net mvc c#

    利用QrCode.Net生成二维码 asp.net mvc c# 里面介绍了.net的方式及js的方式,还不错. 里面用到的qrcode.net的类库下载地址:https://qrcodenet.co ...

  4. ASP.NET 生成二维码(采用ThoughtWorks.QRCode和QrCode.Net两种方式)

    最近做项目遇到生成二维码的问题,发现网上用的最多的是ThoughtWorks.QRCode和QrCode.Net两种方式.访问官网看着例子写了两个Demo,使用过程中发现两个都挺好用的,Thought ...

  5. asp.net生成二维码的方法

    asp.net生成二维码的方法 [复制链接]     这个要利用一个Dll文件. 如下 Gma.QrCodeNet.Encoding.dll (105.5 KB, 下载次数: 27) 当然大家也可以直 ...

  6. asp.net(C#)利用QRCode生成二维码---.NET菜鸟的成长之路

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="QRCode.aspx.cs&q ...

  7. asp.net(C#)利用QRCode生成二维码

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="QRCode.aspx.cs&q ...

  8. ASP.NET生成二维码

    下面使用ThoughtWorks.QRCode.dll这个类库,实现生成二维码 使用时需要增加:下面三个命名空间 using ThoughtWorks.QRCode.Codec; using Thou ...

  9. C#MVC用ZXing.Net生成二维码/条形码

    开篇:zxing.net是.net平台下编解条形码和二维码的工具. 首先创建新项目 选择MVC模板  添加一个控制器  在项目引用中的引用ZXing 进行联网下载 控制器需要引用 后台控制器   pu ...

随机推荐

  1. 阻塞&&非阻塞

    读常规文件是不会阻塞的,不管读多少字节,read一定会在有限的时间内返回.但是从终端设备或网络读则不一定,如果从终端输入的数据没有换行符,调用read读终端设备就会阻塞,如果网络上没有接收到数据包,调 ...

  2. 爬虫python

    最近看到电影,也看了很多的评论,想了解下大多人对相关电影的评论,正好也在学习Python,就利用其爬虫的强大能力,这里利用Python3.6.1 下面是相关代码: #coding:utf-8 __au ...

  3. PAT 甲级 1011 World Cup Betting

    https://pintia.cn/problem-sets/994805342720868352/problems/994805504927186944 With the 2010 FIFA Wor ...

  4. ubuntu16.04 搭建nexus+maven 学习

    /opt/nexus-2.10.0-02/bin vim nexus 关键配置: RUN_AS_USER=root JAVA_HOME=/usr/lib/java/jre export NEXUS_H ...

  5. Scala 基础(6)—— 控制结构

    1. Scala 的内建控制结构 Scala 有几个内建的控制结构,包括: if 表达式 while 循环和 do-while 循环 for 表达式 try 表达式 match 表达式 Scala 的 ...

  6. P1494 [国家集训队]小Z的袜子/莫队学习笔记(误

    P1494 [国家集训队]小Z的袜子 题目描述 作为一个生活散漫的人,小\(Z\)每天早上都要耗费很久从一堆五颜六色的袜子中找出一双来穿.终于有一天,小\(Z\)再也无法忍受这恼人的找袜子过程,于是他 ...

  7. linux查看日志的方法

    linux查看日志文件内容命令tail.cat.tac.head.echo tail -f test.log你会看到屏幕不断有内容被打印出来. 这时候中断第一个进程Ctrl-C, ---------- ...

  8. FreeFileSync

    FreeFileSync is an Open-Source folder comparison and synchronization tool. It is optimized for highe ...

  9. 传输网页数据的json与xml

    #转载请留言联系 1.json json是数据格式,经常用于在网络中,不同平台或者不同语言中进行数据的传输.json的文件后缀就是 .json.当然,也可以把json直接写在js文件中. json储存 ...

  10. 利用Excel导出sql语句

    在工作中遇到了需要用数据库的insert语句,本来是极其简单的事情,但是碰到了有n个(n很大)字段的表,写insert语句就是极其痛苦的事情了,即使只是复制粘贴也是很费力不讨好的一件事.正好手头有ex ...