国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C#如何消除驗證碼圖片的鋸齒效果

2019-10-29 21:21:52
字體:
供稿:網(wǎng)友

引言

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

生成圖片  

1、有鋸齒 

C#消除鋸齒效果,C#如何圖片鋸齒,C#驗證碼消除鋸齒

2、無鋸齒

C#消除鋸齒效果,C#如何圖片鋸齒,C#驗證碼消除鋸齒

生成方法

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();     //清空圖片背景色      //g.Clear(Color.Transparent);      //畫圖片的背景噪音線      /*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);      //畫圖片的前景噪音點(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()));      //}       //畫圖片的邊框線      //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

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持VEVB武林網(wǎng)。


注:相關(guān)教程知識閱讀請移步到c#教程頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 陕西省| 修文县| 宜昌市| 永修县| 仲巴县| 闽清县| 曲水县| 石门县| 鸡西市| 金阳县| 河东区| 澜沧| 鹤岗市| 永平县| 连南| 芮城县| 正宁县| 鄄城县| 襄城县| 泗洪县| 迭部县| 石阡县| 阿瓦提县| 庆元县| 琼中| 赤峰市| 南充市| 丹东市| 广丰县| 聂拉木县| 乾安县| 巴中市| 武宁县| 乐安县| 海阳市| 夏津县| 双鸭山市| 格尔木市| 基隆市| 阿拉善盟| 潼南县|