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

C#如何消除驗(yàn)證碼圖片的鋸齒效果

 更新時(shí)間:2016年09月18日 17:06:21   作者:garfieldzf  
這篇文章主要為大家詳細(xì)介紹了C#如何消除驗(yàn)證碼圖片的鋸齒效果,有無(wú)鋸齒主要依靠一句代碼,想要知道的朋友可閱讀下文

引言 

      基于生成圖片實(shí)現(xiàn)了一個(gè)手機(jī)號(hào)轉(zhuǎn)圖片的需求。 內(nèi)容也很簡(jiǎn)單,直接用手機(jī)號(hào)生成一個(gè)png圖片。就是為了背景透明以便其他地方調(diào)用。 有無(wú)鋸齒主要依靠一句代碼:g.TextRenderingHint= TextRenderingHint.AntiAlias; 

生成圖片  

1、有鋸齒 


2、無(wú)鋸齒

生成方法

string color = "#ff6633"; 

    System.Drawing.Bitmap image = new System.Drawing.Bitmap(170, 35);
    Graphics g = Graphics.FromImage(image);
    try
    {
      g.TextRenderingHint= TextRenderingHint.AntiAlias; //消除鋸齒
      

      //生成隨機(jī)生成器
      Random random = new Random();
     //清空?qǐng)D片背景色
      //g.Clear(Color.Transparent);
      //畫(huà)圖片的背景噪音線(xiàn)

      /*for (int i = 0; i < 2; i++)

      {
        int x1 = random.Next(image.Width);
        int x2 = random.Next(image.Width);
        int y1 = random.Next(image.Height);
        int y2 = random.Next(image.Height);
        g.DrawLine(new Pen(Color.Black), x1, y1, x2, y2);

      }

      */

      System.Drawing.ColorConverter colConvert = new System.Drawing.ColorConverter();
      Color fontColor =(System.Drawing.Color)colConvert.ConvertFromString(color);
      Font font = new System.Drawing.Font("Arial", 18, System.Drawing.FontStyle.Bold);
      LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), fontColor, fontColor,LinearGradientMode.Horizontal);
      g.DrawString(phone, font, brush, 2, 2);
      //畫(huà)圖片的前景噪音點(diǎn)
       //for (int i = 0; i < 50; i++)
      //{
      //  int x = random.Next(image.Width);
      //  int y = random.Next(image.Height);
      //  image.SetPixel(x, y, Color.FromArgb(random.Next()));

      //}

 

      //畫(huà)圖片的邊框線(xiàn)

      //g.DrawRectangle(new Pen(Color.White), 0, 0, image.Width - 1, image.Height - 1);

 

      System.IO.MemoryStream ms = new System.IO.MemoryStream();
      Color backColor = image.GetPixel(1, 1);
      image.MakeTransparent(backColor);
      image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
      context.Response.ClearContent();
      context.Response.ContentType = "image/x-png";
      context.Response.BinaryWrite(ms.ToArray());
    }
    finally
    {
      g.Dispose();
      image.Dispose();

    }

參考資料 

http://www.blue1000.com/bkhtml/c17/2013-03/71115.htm

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

饶河县| 鄂托克前旗| 孟津县| 中宁县| 乌拉特后旗| 平利县| 正安县| 曲松县| 黑水县| 忻城县| 青田县| 紫阳县| 肥西县| 合山市| 汨罗市| 丽水市| 竹北市| 渭南市| 永登县| 平顶山市| 宿松县| 那坡县| 邢台县| 晋宁县| 襄城县| 日喀则市| 攀枝花市| 宁德市| 榆中县| 九寨沟县| 孙吴县| 昭通市| 泰和县| 同心县| 凤山市| 天全县| 衡南县| 固原市| 广州市| 南皮县| 靖安县|