在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
Bitmap bitmap = null; bitmap = new Bitmap(Width, Height); Graphics g = Graphics.FromImage(bitmap); //设置画笔 Color color = ColorTranslator.FromHtml(FontColor); Brush brush = new SolidBrush(color); //设置字体 FontStyle ftStyle = new FontStyle(); if (fontStyle.ToLower() == "italic" && FontWeight.ToLower() == "bold") ftStyle = FontStyle.Italic | FontStyle.Bold; } else if (fontStyle.ToLower() == "italic" && FontWeight.ToLower() != "bold") ftStyle = FontStyle.Italic; } else if (fontStyle.ToLower() != "italic" && FontWeight.ToLower() == "bold") ftStyle = FontStyle.Bold; } else ftStyle = FontStyle.Regular; } Font font; font = new Font(FamilyName, intFontSize, ftStyle, GraphicsUnit.Pixel); //设置绘图区域 RectangleF rect = new RectangleF(0, 0, Width, Height); //设置文本绘制格式 StringFormat stringFormat = new StringFormat(); if (TextAlign.ToLower() == "center") stringFormat.LineAlignment = StringAlignment.Center; } else if (TextAlign.ToLower() == "right") stringFormat.LineAlignment = StringAlignment.Far; } else stringFormat.LineAlignment = StringAlignment.Near; } //设置绘图质量 g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.SmoothingMode = SmoothingMode.HighQuality; g.PixelOffsetMode = PixelOffsetMode.HighQuality; g.CompositingMode = CompositingMode.SourceOver; g.CompositingQuality = CompositingQuality.HighQuality; g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit; g.PageUnit = GraphicsUnit.Pixel; //设置透明背景 g.Clear(Color.Transparent); //绘制字符串 g.DrawString(Text, font, brush, rect, stringFormat); //取浏览器版本,IE6显示透明gif,其它则显示透明png if (GetBrowsetype() == "IE" && GetBrowseVersion() == "6.0") bitmap = MakeTransparentGif(bitmap, Color.Black); System.IO.MemoryStream ms = new System.IO.MemoryStream(); bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Gif); byte[] bytes = ms.GetBuffer(); g.Dispose(); bitmap.Dispose(); Response.Clear(); Response.ContentType = "image/Gif"; Response.BinaryWrite(bytes); } else System.IO.MemoryStream ms = new System.IO.MemoryStream(); bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png); byte[] bytes = ms.GetBuffer(); g.Dispose(); bitmap.Dispose(); Response.Clear(); Response.ContentType = "image/Png"; Response.BinaryWrite(bytes); } } System.Web.HttpBrowserCapabilities browser = System.Web.HttpContext.Current.Request.Browser; return browser.Version; } public static string GetBrowsetype() System.Web.HttpBrowserCapabilities browser = System.Web.HttpContext.Current.Request.Browser; return browser.Browser; } |
请发表评论