一 C#的二维码

   示例:

    class Program
{
static void Main(string[] args)
{
QrEncoder qrEncoder = new QrEncoder(ErrorCorrectionLevel.H);
QrCode qrCode = new QrCode();
qrEncoder.TryEncode("菡,现在想起你,真的是太突然了,你跳个舞给我看嘛,能不能不要这么诱人啊,我已经逻辑混乱了", out qrCode);
int ModuleSize = ; //大小
QuietZoneModules QuietZones = QuietZoneModules.Two; //空白区域
var render = new GraphicsRenderer(new FixedModuleSize(ModuleSize, QuietZones));
using (System.IO.Stream stream = File.OpenWrite(@"E:\RuPeng_Project\DiDao\DIDAO.Front\News\11\8.png"))
{
render.WriteToStream(qrCode.Matrix,System.Drawing.Imaging.ImageFormat.Png, stream);
}
}
}

Program.cs

   实例:

1 当新闻静态化时,获得这个文章的url,
2 把这个文章的url写入新路径的图片
3 这个图片可以在原来url的img标签显示出来

        /// <summary>
/// 对于每一篇文章url,生成一个二维码
/// </summary>
/// <param name="ViewStaticDirecPre">二维码所在目录前缀</param>
/// <param name="categoryId">文章的类别id</param>
/// <param name="id">文章id</param>
public static void CreateQrCode(string ViewStaticDirecPre, long categoryId, long id)
{
string newsUrl = "http://localhost:19826/News/" + categoryId + "/" + id + ".shtml"; //文章地址路径url
string qrCodePath = Path.Combine(ViewStaticDirecPre, categoryId + "\\" + id + ".png"); //生成的二维码路径
string qrPath = Path.GetDirectoryName(qrCodePath);
if (!Directory.Exists(qrPath))
{
Directory.CreateDirectory(qrPath);
}
QrEncoder qrEncoder = new QrEncoder(ErrorCorrectionLevel.H);
QrCode qrCode = new QrCode();
qrEncoder.TryEncode(newsUrl, out qrCode);
int ModuleSize = ; //大小
QuietZoneModules QuietZones = QuietZoneModules.Two; //空白区域
var render = new GraphicsRenderer(new FixedModuleSize(ModuleSize, QuietZones));
using (System.IO.Stream stream = File.OpenWrite(qrCodePath))
{
render.WriteToStream(qrCode.Matrix, System.Drawing.Imaging.ImageFormat.Png, stream);
}
}

二 JavaScript的二维码

    分享一下:jq生成二维码,不用再生成一堆png了。
<script src="/js/jquery.qrcode-0.11.0.min.js"></script>
<script type="text/javascript">
$(function () {
$("#qrcode").qrcode({
//render: "table", //table方式
width: , //宽度
height: , //高度
text: "http://localhost:6158/News/@(Model.CategoryId)/@(Model.Id).shtml" //任意内容
});
})
</script>

最新文章

  1. How those spring enable annotations work--转
  2. MinGW安装c-c++
  3. Fort.js – 时尚、现代的表单填写进度提示效果
  4. python查找算法的实现-二分法
  5. 基于Extjs的web表单设计器 第六节——界面框架设计
  6. [流媒体]live555简介(转)
  7. 第三百三十七天 how can I 坚持
  8. Java中的toString()方法
  9. Obout - ASP.NET HTML Editor
  10. Symfony VarDumper Component
  11. Java MD5校验
  12. js求字符长度
  13. C 语言字符 和字符串输出
  14. 脑波设备mindwave介绍
  15. MVC json
  16. Eclipse plugin web site 发布和版本更新
  17. React Native 系列(四) -- 布局
  18. LeetCode(36)- Implement Stack using Queues
  19. 【Vagrant】-NO.130.Vagrant.1 -【Vagrant】
  20. selenium下打开Chrome报错解决

热门文章

  1. Python绿色版
  2. linux下安装eclipse并使用xstart远程使用(centos7)
  3. java.lang.ClassFormatError Duplicate field name&amp;signature in class file XXXXXX【转】
  4. poj 1961 Period 【KMP-next前缀数组的应用】
  5. mybaties mapping中if
  6. review10
  7. jsonp 解决跨域传输
  8. 程序员怎样迈出从5K到1W的重要一步
  9. C语言基础二
  10. 常用的linux基础命令