C# 生成一个带数字的饼图

 


using
System; using System.Collections.Generic; using System.Drawing; using System.Drawing.Drawing2D; using System.Linq; using System.Text; namespace Image.Util { class ShapeImage { /// <summary> /// 画一个带数字的饼图 /// </summary> /// <param name="digit"></param> /// <param name="color"></param> /// <returns></returns> public static Bitmap GetPieWithDigit(int digit,Color color) { int size = 16; if ((digit < 0) || (digit > 99)) throw new Exception("数值超范围"); Bitmap bmp = new Bitmap(size, size); Graphics g = Graphics.FromImage(bmp); g.SmoothingMode = SmoothingMode.AntiAlias; //使绘图质量最高,即消除锯齿 g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.CompositingQuality = CompositingQuality.HighQuality; g.FillPie(new SolidBrush(color), new Rectangle(0, 0, size-1, size-1), 0, 360); Point centerPoint = new Point(size / 4, size / 4); StringFormat stringFormat = new StringFormat(); stringFormat.Alignment = StringAlignment.Center; if (digit.ToString().Length == 2) { g.DrawString(digit.ToString(), new Font("微软雅黑", 9), new SolidBrush(Color.White), new Rectangle(0, 0, size, size), stringFormat); } else g.DrawString(digit.ToString(), new Font("微软雅黑", 9), new SolidBrush(Color.White), new Rectangle(0, 0, size, size), stringFormat); return bmp; } } }

 

posted @ 2018-01-31 15:34  zhaogaojian  阅读(1342)  评论(0编辑  收藏  举报