欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

asp.net(C#)使用QRCode生成圖片中心加Logo或圖像的二維碼實(shí)例

 更新時間:2016年06月27日 16:07:09   作者:smartsmile2012  
這篇文章主要介紹了asp.net(C#)使用QRCode生成圖片中心加Logo或圖像的二維碼,結(jié)合實(shí)例形式詳細(xì)分析了asp.net基于QRCode生成二維碼的具體實(shí)現(xiàn)技巧,需要的朋友可以參考下

本文實(shí)例講述了asp.net(C#)使用QRCode生成圖片中心加Logo或圖像的二維碼。分享給大家供大家參考,具體如下:

<%@ WebHandler Language="C#" Class="GetQRCode" %>
using System;
using System.Web;
using ThoughtWorks.QRCode.Codec;
using ThoughtWorks.QRCode.Codec.Data;
using ThoughtWorks.QRCode.Codec.Util;
using System.IO;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
public class GetQRCode : IHttpHandler
{
  public void ProcessRequest(HttpContext context)
  {
    String data = context.Request["CodeText"];
    if (!string.IsNullOrEmpty(data))
    {
      QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
      qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;
      qrCodeEncoder.QRCodeScale = 4;
      qrCodeEncoder.QRCodeVersion = 8;
      qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;
      System.Drawing.Image image = qrCodeEncoder.Encode(data);
      System.IO.MemoryStream MStream = new System.IO.MemoryStream();
      image.Save(MStream, System.Drawing.Imaging.ImageFormat.Png);
      System.IO.MemoryStream MStream1 = new System.IO.MemoryStream();
      CombinImage(image, context.Server.MapPath("~/images/201292891051540.jpg")).Save(MStream1, System.Drawing.Imaging.ImageFormat.Png);
      context.Response.ClearContent();
      context.Response.ContentType = "image/png";
      context.Response.BinaryWrite(MStream1.ToArray());
      //image.Dispose();
      MStream.Dispose();
      MStream1.Dispose();
    }
    context.Response.Flush();
    context.Response.End();
  }
  /// <summary>
  /// 調(diào)用此函數(shù)后使此兩種圖片合并,類似相冊,有個
  /// 背景圖,中間貼自己的目標(biāo)圖片
  /// </summary>
  /// <param name="imgBack">粘貼的源圖片</param>
  /// <param name="destImg">粘貼的目標(biāo)圖片</param>
  public static Image CombinImage(Image imgBack, string destImg)
  {
    Image img = Image.FromFile(destImg);    //照片圖片
    if (img.Height != 65 || img.Width != 65)
    {
      img = KiResizeImage(img, 65, 65, 0);
    }
    Graphics g = Graphics.FromImage(imgBack);
    g.DrawImage(imgBack, 0, 0, imgBack.Width, imgBack.Height);   //g.DrawImage(imgBack, 0, 0, 相框?qū)? 相框高);
    //g.FillRectangle(System.Drawing.Brushes.White, imgBack.Width / 2 - img.Width / 2 - 1, imgBack.Width / 2 - img.Width / 2 - 1,1,1);//相片四周刷一層黑色邊框
    //g.DrawImage(img, 照片與相框的左邊距, 照片與相框的上邊距, 照片寬, 照片高);
    g.DrawImage(img, imgBack.Width / 2 - img.Width / 2, imgBack.Width / 2 - img.Width / 2, img.Width, img.Height);
    GC.Collect();
    return imgBack;
  }
  /// <summary>
  /// Resize圖片
  /// </summary>
  /// <param name="bmp">原始Bitmap</param>
  /// <param name="newW">新的寬度</param>
  /// <param name="newH">新的高度</param>
  /// <param name="Mode">保留著,暫時未用</param>
  /// <returns>處理以后的圖片</returns>
  public static Image KiResizeImage(Image bmp, int newW, int newH, int Mode)
  {
    try
    {
      Image b = new Bitmap(newW, newH);
      Graphics g = Graphics.FromImage(b);
      // 插值算法的質(zhì)量
      g.InterpolationMode = InterpolationMode.HighQualityBicubic;
      g.DrawImage(bmp, new Rectangle(0, 0, newW, newH), new Rectangle(0, 0, bmp.Width, bmp.Height), GraphicsUnit.Pixel);
      g.Dispose();
      return b;
    }
    catch
    {
      return null;
    }
  }
  public bool IsReusable
  {
    get
    {
      return false;
    }
  }
}

運(yùn)行效果如下圖所示:

PS:本站還提供了一個功能十分強(qiáng)悍的在線二維碼生成工具,可實(shí)現(xiàn)文本、電話號碼、短信、郵件、網(wǎng)址等的二維碼生成及l(fā)ogo圖標(biāo)添加功能:

在線生成二維碼工具(加強(qiáng)版):
http://tools.jb51.net/transcoding/jb51qrcode

更多關(guān)于asp.net相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《asp.net操作json技巧總結(jié)》、《asp.net字符串操作技巧匯總》、《asp.net操作XML技巧總結(jié)》、《asp.net文件操作技巧匯總》、《asp.net ajax技巧總結(jié)專題》及《asp.net緩存操作技巧總結(jié)》。

希望本文所述對大家asp.net程序設(shè)計有所幫助。

相關(guān)文章

最新評論