English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
서론
이미지 생성 기반으로 전화번호를 이미지로 변환하는 요구사항을 구현했습니다. 내용은 매우 간단합니다. 전화번호를 사용하여 png 이미지를 생성합니다. 배경이 투명하여 다른 곳에서 호출하기 위해 만들었습니다. 경계선이 있는지 없는지는 하나의 코드에 의존합니다: g.TextRenderingHint = TextRenderingHint.AntiAlias;
이미지 생성
1、경계선이 있음
2、무 경계선
생성 방법
string color = "#ff6633";"} System.Drawing.Bitmap image = new System.Drawing.Bitmap(170, 35); Graphics g = Graphics.FromImage(image); try { g.TextRenderingHint= TextRenderingHint.AntiAlias; //사각형 제거 //랜덤 생성기를 생성합니다 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); //그림의 전경 노이즈 포인트를 그립니다 //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
이것이 본 문서의 모든 내용입니다. 여러분의 학습에 도움이 되길 바랍니다. 또한, 노래 튜토리얼을 많이 지지해 주시길 바랍니다.
고지: 본 내용은 인터넷에서 가져왔으며, 저작권자가 소유하고 있으며, 인터넷 사용자가 자발적으로 기여하고 업로드한 내용입니다. 이 사이트는 소유권을 가지지 않으며, 인공 편집 처리를 하지 않았으며, 관련 법적 책임도 부담하지 않습니다. 저작권 문제가 있으면 이메일로 notice#w에 보내주세요.3codebox.com(이메일을 보내면, #을 @으로 변경해 주세요. 신고하고 관련 증거를 제공하시면, 사이트가 즉시 위반된 내용을 삭제합니다。)