最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

c#裁剪圖片后使用zxing生成二維碼示例分享

 更新時間:2014年01月17日 11:19:08   作者:  
這篇文章主要介紹了c#裁剪圖片后使用zxing生成二維碼的示例,大家參考使用吧

復制代碼 代碼如下:

/// <summary>
/// 生成二維碼
/// </summary>
/// <param name="fileName">生成二維碼路徑</param>
/// <param name="url">生成的內容</param>
/// <param name="width">二維碼寬</param>
/// <param name="height">二維碼高</param>
/// <param name="userFace">需生成的Logo圖片</param>
/// <returns></returns>
private Bitmap GetCodeImgUrl(string fileName, string url, int width, int height, string userFace)
{

    BarcodeWriter writer = new BarcodeWriter
    {
        Format = BarcodeFormat.QR_CODE,
        Renderer = new BitmapRenderer
        {
            Foreground = Color.Black
        },
        Options = new ZXing.QrCode.QrCodeEncodingOptions
        {
            DisableECI = true,
            Height = height,
            Width = width,
            Margin = 0,
            CharacterSet = "UTF-8",
            ErrorCorrection = ErrorCorrectionLevel.M
        }
    };

    Bitmap bitmap = writer.Write(url);
    if (!string.IsNullOrEmpty(userFace))
    {
        Bitmap bits = (System.Drawing.Bitmap)System.Drawing.Image.FromFile(userFace);
        if (bits != null)
        {                   
            //剪裁一個80*80的Logo圖片
            ImageCut img = new ImageCut(0, 0, 80, 80);
            System.Drawing.Bitmap icon = img.KiCut(bits);
            //userFace_b.jpg是一個邊框的圖片
            Bitmap bits2 = new System.Drawing.Bitmap((System.Drawing.Bitmap)System.Drawing.Image.FromFile(Application.StartupPath + "/user/userFace_b.jpg"), 84, 84);
            if (icon != null)
            {
                try
                { 
                    //畫了2個邊框,一個是logo,一個在logo周圍加了一個邊框
                    using (var graphics = System.Drawing.Graphics.FromImage(bitmap))
                    {
                        graphics.DrawImage(bits2, (bitmap.Width - bits2.Width) / 2, (bitmap.Height - bits2.Height) / 2);
                        graphics.DrawImage(icon, (bitmap.Width - icon.Width) / 2, (bitmap.Height - icon.Height) / 2);

                    }

                }
                catch (Exception ex)
                {

                }
                finally
                {
                    icon.Dispose();
                    GC.Collect();

                }
            }
            bitmap.Save(fileName, ImageFormat.Jpeg);
        }

    }

    return bitmap;
}

復制代碼 代碼如下:

public class ImageCut
  {

      /// <summary>
      /// 剪裁 -- 用GDI+
      /// </summary>
      /// <param name="b">原始Bitmap</param>
      /// <param name="StartX">開始坐標X</param>
      /// <param name="StartY">開始坐標Y</param>
      /// <param name="iWidth">寬度</param>
      /// <param name="iHeight">高度</param>
      /// <returns>剪裁后的Bitmap</returns>
      public Bitmap KiCut(Bitmap b)
      {
          if (b == null)
          {
              return null;
          }
          int w = b.Width;
          int h = b.Height;
          int intWidth = 0;
          int intHeight = 0;
          if (h * Width / w > Height)
          {
              intWidth = Width;
              intHeight = h * Width / w;

          }
          else if (h * Width / w < Height)
          {
              intWidth = w * Height / h;
              intHeight = Height;

          }
          else
          {
              intWidth = Width;
              intHeight = Height;
          }

          Bitmap bmpOut_b = new System.Drawing.Bitmap(b, intWidth, intHeight);
          w = bmpOut_b.Width;
          h = bmpOut_b.Height;
        

          if (X >= w || Y >= h)
          {
              return null;
          }

          if (X + Width > w)
          {
              Width = w - X;
          }
          else
          {
              X = (w-Width) / 2;
          }

          if (Y + Height > h)
          {
              Height = h - Y;
          }
        

 

          try
          {
              Bitmap bmpOut = new Bitmap(Width, Height, PixelFormat.Format24bppRgb);            
              Graphics g = Graphics.FromImage(bmpOut);
              g.DrawImage(bmpOut_b, new Rectangle(0, 0, Width, Height), new Rectangle(X, Y, Width, Height), GraphicsUnit.Pixel);
              g.Dispose();

              return bmpOut;
          }
          catch
          {
              return null;
          }
      }

      public int X = 0;
      public int Y = 0;
      public int Width = 120;
      public int Height = 120;
      public ImageCut(int x, int y, int width, int heigth)
      {
          X = x;
          Y = y;
          Width = width;
          Height = heigth;
      }
  }

復制代碼 代碼如下:

  private void btnSubmit_Click(object sender, EventArgs e)
        {
            string UserId = "1245460396";   

            string curFilePath = "/user/";

            string curFileName_b = "DimensionalPig_" + UserId + "_b";
            string path = Application.StartupPath + curFilePath;
            if (Directory.Exists(path) == false)//如果不存在就創(chuàng)建file文件夾
            {
                Directory.CreateDirectory(path);
            }
            string fileName_b = Application.StartupPath + curFilePath + "/" + curFileName_b + ".jpg";//獲得上傳文件名

            string UserUrl = string.Format("http://www.fzitv.net/u{0}", UserId.Trim());
            string userFace_b = Application.StartupPath + "/user/" + UserId + "_b.jpg";

            Bitmap bitmap_b = GetCodeImgUrl(fileName_b.Replace("_b.", "_b_ewm."), UserUrl, 400, 400, userFace_b);
            this.p.Image =(System.Drawing.Image)bitmap_b;
this.p.Image.Save(fileName_b.Replace("_b.", "_b_ewm."));

相關文章

  • c# 適配器模式

    c# 適配器模式

    適配器模式:將一個類的接口轉換成客戶希望的另一個接口,Adapter使原本由于接口不兼容而不能一起工作的那些類可以一起工作
    2012-10-10
  • C#操作windows系統(tǒng)進程的方法

    C#操作windows系統(tǒng)進程的方法

    這篇文章主要介紹了C#操作windows系統(tǒng)進程的方法,涉及C#針對windows操作系統(tǒng)進程的創(chuàng)建與關閉的技巧,需要的朋友可以參考下
    2015-04-04
  • C#實現強制關閉當前程序進程

    C#實現強制關閉當前程序進程

    這篇文章主要介紹了C#實現強制關閉當前程序進程,本文直接給出實現代碼,可以實現完全Kill掉不留痕跡,需要的朋友可以參考下
    2015-06-06
  • C#判斷ip地址是否可以ping的通

    C#判斷ip地址是否可以ping的通

    這篇文章主要介紹了ip地址是否可以ping的通的方法,使用到了C#,需要的朋友可以參考下
    2014-06-06
  • c#操作xml幫助類分享(xml增刪改查)

    c#操作xml幫助類分享(xml增刪改查)

    c#操作xml幫助類XMLHelper源碼分享,實現對XML文檔的創(chuàng)建,及節(jié)點和屬性的增、刪、改、查
    2014-01-01
  • C#實現鼠標移動到曲線圖上顯示值的方法

    C#實現鼠標移動到曲線圖上顯示值的方法

    這篇文章主要介紹了C#實現鼠標移動到曲線圖上顯示值的方法,是C#的WinForm窗體程序設計中非常實用的技巧,需要的朋友可以參考下
    2014-10-10
  • C# 刪除數組內的某個值、一組值方法詳解

    C# 刪除數組內的某個值、一組值方法詳解

    在本篇文章里小編給大家整理的是關于C# 如何刪除數組內的某個值、一組值的相關知識點,需要的朋友們學習下。
    2020-03-03
  • C# RGB圖像和灰度圖像互轉的實現

    C# RGB圖像和灰度圖像互轉的實現

    在我們的圖像類型教程中定義了RGB顏色模型和灰度格式,本文主要介紹了C# RGB圖像和灰度圖像互轉的實現,文中通過代碼介紹的非常清楚,具有一定的參考價值,感興趣的可以了解一下
    2023-08-08
  • unity實現手游虛擬搖桿

    unity實現手游虛擬搖桿

    這篇文章主要為大家詳細介紹了unity實現手游虛擬搖桿,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-04-04
  • c# 對CSV文件操作(寫入、讀取、修改)

    c# 對CSV文件操作(寫入、讀取、修改)

    這篇文章主要介紹了c# 如何對CSV文件操作,幫助大家更好的理解和學習C#,感興趣的朋友可以了解下
    2020-08-08

最新評論

闸北区| 馆陶县| 香港| 汾阳市| 顺昌县| 乐山市| 武山县| 陕西省| 靖西县| 永仁县| 龙陵县| 礼泉县| 醴陵市| 万年县| 宁城县| 平塘县| 雅安市| 神农架林区| 郑州市| 惠东县| 宁武县| 永昌县| 闸北区| 罗甸县| 九台市| 三台县| 凌源市| 澄迈县| 菏泽市| 尚志市| 杂多县| 驻马店市| 苏尼特左旗| 福鼎市| 宜州市| 定襄县| 新乡县| 望谟县| 房山区| 虹口区| 化德县|