主攻ASP.NET.4.5 MVC4.0之重生:二维码生成和谷歌二维码

使用ThoughtWorks.QRCode.Codec

 

 

效果图

主攻ASP.NET.4.5 MVC4.0之重生:二维码生成和谷歌二维码

using ThoughtWorks.QRCode.Codec;

 

非原创代码

 1         public void code(string id)

 2         {

 3             QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();

 4             qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;

 5             qrCodeEncoder.QRCodeScale = 4;

 6             qrCodeEncoder.QRCodeVersion = 5;

 7             qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;

 8             string data = "http://" + Request.Url.Host.ToString() + "/"+id;

 9             System.Drawing.Bitmap image = qrCodeEncoder.Encode(data);

10             System.IO.MemoryStream MStream = new System.IO.MemoryStream();

11             image.Save(MStream, System.Drawing.Imaging.ImageFormat.Gif);

12             Response.ClearContent();

13             Response.ContentType = "image/Gif";

14             Response.BinaryWrite(MStream.ToArray());

15         }
 1   <div style="height: 127px; width: 300px;">

 2                     <img id="code" width="120" height="120" src="/code/@{@Model.user.LogName}"

 3                                         alt="二维码" /><!--MVC-->

 4                      <script type="text/javascript"><!--谷歌-->

 5 

 6                         document.write("<img style=\"float:left;\" src=\"https://chart.googleapis.com/chart?cht=qr&chs=500x500&choe=UTF-8&chld=L|2&chl=");

 7 

 8                         document.write(window.location.href);

 9 

10                         document.write("\" width=\"120\" height=\"120\" alt=\"二维码\"/>");

11 

12                     </script>13                     <span style="float: right; width: 160px; margin-top: 5px; line-height: 200%;">

14                         <span class="red">[多终端浏览]</span><br />

15                         扫描后您可以在手机、平板电脑等移动设备上继续浏览

16 

17                     </span>

18 

19                 </div>

 

 

你可能感兴趣的:(asp.net)