如何使用APS.NET MVC4生成二维码
发表于:2025-11-08 作者:千家信息网编辑
千家信息网最后更新 2025年11月08日,本篇内容主要讲解"如何使用APS.NET MVC4生成二维码",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"如何使用APS.NET MVC4生成二维码"吧!
千家信息网最后更新 2025年11月08日如何使用APS.NET MVC4生成二维码
本篇内容主要讲解"如何使用APS.NET MVC4生成二维码",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"如何使用APS.NET MVC4生成二维码"吧!
一、视图
@{ Layout = null;} Index
二、控制器
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);//保存位图 string imageUrl = "/Content/Images/QRImages/" + timeStr + ".jpg";//显示图片 return 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); } }}三、二维码生成工具类
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 { /// /// 生成二维码 /// /// 要编码的内容 /// 返回二维码位图 public static Bitmap QRCodeEncoderUtil(string qrCodeContent) { QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(); qrCodeEncoder.QRCodeVersion = 0; Bitmap img = qrCodeEncoder.Encode(qrCodeContent, Encoding.UTF8);//指定utf-8编码, 支持中文 return img; } /// /// 解析二维码 /// /// 要解析的二维码位图 /// 解析后的字符串 public static string QRCodeDecoderUtil(Bitmap bitmap) { QRCodeDecoder decoder = new QRCodeDecoder(); string decodedString = decoder.decode(new QRCodeBitmapImage(bitmap), Encoding.UTF8);//指定utf-8编码, 支持中文 return decodedString; } }}到此,相信大家对"如何使用APS.NET MVC4生成二维码"有了更深的了解,不妨来实际操作一番吧!这里是网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
二维
二维码
生成
位图
内容
编码
图片
utf-8
中文
学习
支持
实用
更深
兴趣
名称
字符
字符串
实用性
实际
工具
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
软件开发的技术支持怎么写
杭州至美焕新网络技术
医院信息系统可能使用的数据库
广水数据库
u8初始化数据库能解决
商盟互联网科技
法院 打击网络安全犯罪
关于网络技术的软文
金蝶记账王数据库
有没有柴油车数据库
sql数据库技术与应用试题
品牌网络技术咨询介绍
深圳软件开发市场价
网络安全知识团日活动
南阳软件开发税务筹划解决方案
怎么将数据库的数据导入报表中
亚马逊系统软件开发
如何设置显示无法连接到服务器
万方数据库论文怎么打不开
sql空间数据库安全性
软件开发常见流程
万方数据库专利查询
软件开发配置管理文档
哪些专业学习数据库概论
数据库做web连接
阿里云服务器如何配置内部
带离线下载的服务器
网络安全教育记录
dns服务器电脑怎么设
苹果谷歌服务器名字