c语言给坐标画图像,用c语言编程 编写画线段,圆 ,椭圆图形,并填充颜色的程序...

private void CreateImg()         {             String[] m = m1;

if (getMax() >= 60 && getMax() < 80)             {                 m = m2;             }             else if (getMax() >= 80)             {                 m = m3;             }

int height = Convert.ToInt32(ImgHeight), width = Convert.ToInt32(ImgWidth);             Bitmap image = new Bitmap(width, height);             //创建Graphics类对象             Graphics g = Graphics.FromImage(image);             try             {                 Font font = xTextFont;//X轴字体                 Font font2 = yTextFont;//Y轴字体                 LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height),                 Color.Blue, Color.BlueViolet, 1.2f, true);                 g.FillRectangle(Brushes.WhiteSmoke, 0, 0, width, height);                 g.Clear(Color.Transparent);//此代码放的位置决定显示//清空图片背景色为透明                  //g.Clear(Color.White);                 // Brush brush1 = new SolidBrush(Color.Blue);                 //g.DrawString("成绩统计柱状图", font1, brush, new PointF(70, 30));                 //画图片的边框线                 //g.DrawRectangle(new Pen(Color.Blue), 0, 0, image.Width - 1, image.Height - 1);                          //绘制线条                 //绘制竖向线条                 //for (int i = 0; i < 14; i++)                 //{                 //g.DrawLine(mypen, x, 80, x, 340);//绘制除y轴外的其它竖向线条                 //    x = x + 40;                 //}                            //x = 0;                 //绘制横向线条                 //for (int i = 0; i < 9; i++)                 //{                 //g.DrawLine(mypen, 60, y, 620, y);//绘制除x轴外的横向线条                 //    y = y + 26;                 //}                 Pen mypen = new Pen(brush, 1);                 Pen mypen1 = new Pen(yColor, pyWidth);                 g.DrawLine(mypen1, xWidth, 0, xWidth, height - yHeight);//绘制y轴                 Pen mypen2 = new Pen(xColor, pxWidth);                 g.DrawLine(mypen2, xWidth, height - yHeight, width, height - yHeight);//绘制X轴                 //x轴                 int xrowWidth = (int)(Math.Ceiling(g.MeasureString(getTextWidth(), font).Width));//文字的宽度                 int xrowHeight = (int)(Math.Ceiling(g.MeasureString("测试", font, 100, StringFormat.GenericTypographic).Height));//文字的高度                 int xspan = (int)Math.Ceiling((float)(Convert.ToInt32(ImgWidth) - xWidth - chartXSpan - pyWidth - xrowWidth) / (cachede.Count - 1));//绘制的坐标为起始坐标,正常绘制的长度会多出一组字符串的长度(长度为x,绘制n组字符串,则算坐标区间时应减去一组字符串的长度)                 int x = xWidth + chartXSpan;                 foreach (KeyValuePair kvp in cachede)                 {                     g.DrawString(kvp.Key, font, xTextBrush, x, Convert.ToInt32(ImgHeight) - xrowHeight); //设置文字内容及输出位置                     x = x + xspan;                 }                 //y轴                 int yspan = 0;                 int rowHeight = (int)(Math.Ceiling(g.MeasureString("50", font2).Height));//文字的高度                 int y = Convert.ToInt32(ImgHeight) - yHeight - rowHeight - pxWidth;                 yspan = (int)Math.Ceiling((float)(Convert.ToInt32(ImgHeight) - yHeight - pxWidth - (rowHeight + ytopspan)) / (m.Length - 1));//减去rowHeight+20:绘制长度y减去了一个rowheight,此处算yspan时也要减去,另外20是留出y轴最后的文字与顶端的距离。                 for (int i = 0; i < m.Length; i++)                 {                     g.DrawString(m[i].ToString(), font2, yTextBrush, 0, y); //设置文字内容及输出位置                     y = y - yspan;                 }                 //绘制柱状图.                 int ximg = xWidth + chartXSpan;//绘制图x轴坐标点                 int textwidth = 0;//文字的宽度                 int ximgspan = 0;//绘制图形与对应X轴文字对应位置                 SolidBrush mybrush = new SolidBrush(chartColor);                 foreach (KeyValuePair kvp in cachede) //绘制x轴柱状图                 {                     textwidth = (int)(Math.Ceiling(g.MeasureString(kvp.Key, font).Width));                     ximgspan = (int)Math.Ceiling((float)(textwidth - chartWidth) / 2);                     //考虑显示最高的百分比数值                     int yRealHeight = (int)Math.Ceiling((float)((Convert.ToInt32(ImgHeight) - yHeight - pxWidth - ytopspan) * 100 * Convert.ToDouble(kvp.Value)) / (100 * getMaxY(m)));//计算柱状图所占高度                     g.FillRectangle(mybrush, ximg + ximgspan, ImgHeight - yHeight - pxWidth - yRealHeight, chartWidth, yRealHeight);                     g.DrawString(kvp.Value + "%", chartTextFont, chartTextBrush, ximg + ximgspan - 5, ImgHeight - yHeight - pxWidth - yRealHeight - rowHeight);                     ximg = ximg + xspan;                 }                 //绘制标识                 //Font font3 = new System.Drawing.Font("Arial", 10, FontStyle.Regular);                 //g.DrawRectangle(new Pen(Brushes.Blue), 170, 400, 250, 50); //绘制范围框                 //g.FillRectangle(Brushes.Red, 270, 410, 20, 10); //绘制小矩形                 //g.DrawString("报名人数", font3, Brushes.Red, 292, 408);                 //g.FillRectangle(Brushes.Green, 270, 430, 20, 10);                 //g.DrawString("通过人数", font3, Brushes.Green, 292, 428);                 System.IO.MemoryStream ms = new System.IO.MemoryStream();                 image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);                 System.Web.HttpContext.Current.Response.ClearContent();                 System.Web.HttpContext.Current.Response.ContentType = "image/Png";                 System.Web.HttpContext.Current.Response.BinaryWrite(ms.ToArray());             }             finally             {                 g.Dispose();                 image.Dispose();             }         }

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值