#region 生成折线图
public static string DrawImage(float[] oFloat, bool isText,string path) {
#region 数值
int width = 660; //图片宽度
int height = 220; //图片高度
int iX = 20; //左,下方向留白
int iH = height - 20; //显示区域高度
int iW = width - 20; //显示区域宽度 float fHeight = 200; //纵轴总长度
float fVirtualHeight = fHeight; //虚拟总长度
//算出最大的正整数,如输入300,则最大数为400
float fTempMaxNum = MaxFloat(oFloat);
while (fVirtualHeight < fTempMaxNum) {
fVirtualHeight += 100;
}
float fCount = 10; //纵轴分成10份,固定
float fPx = fHeight / fCount; //每份多少像素,固定
float fRmb = fVirtualHeight / fCount; //每份表示多少钱,根据参数中最大数决定
float fPPx = fPx / fRmb; //每钱多少像素,
#endregion #region 构造图用
//构造BITMAP
Bitmap oBmap = new Bitmap(width, height); //新建一个画板
Graphics g = Graphics.FromImage(oBmap);
//设置高质量插值法
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
//设置高质量,低速度呈现平滑程度
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; //清空画布并以透明背景色填充
g.Clear(Color.White); //新建钢笔,灰色,1px
Pen oPen = new Pen(Color.Gray);
Pen oSpen = new Pen(Color.Silver);
Pen oRpen = new Pen(Color.Red); //定义黑色过渡型笔刷
LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, oBmap.Width, oBmap.Height), Color.Black, Color.Black, 1.2F, true);
LinearGradientBrush brush_red = new LinearGradientBrush(new Rectangle(0, 0, oBmap.Width, oBmap.Height), Color.Red, Color.Red, 1.2F, true); #endregion //计算宽度,高度份数
float wLens = iW / oFloat.Length; #region 画横纵坐标
//线帽
oPen.EndCap = LineCap.ArrowAnchor;
//画横纵坐标
g.DrawLine(oPen, iX, iH, iX, iX - 10);
g.DrawString("y", new Font("Arial", 8), brush, 25, 1);
g.DrawLine(oPen, iX, iH, iW + 10, iH);
g.DrawString("x", new Font("Arial", 8), brush, iW + 10, iH - 1);
//输出标题
//g.DrawString(string.Format("CreateDate {0}", DateTime.Now.ToString()), new Font("Arial", 8), brush, iW / 2, 1);
#endregion #region 画横坐标
//画横坐标
for (int i = 0; i < oFloat.Length; i++) {
//输出小竖线
if (i == DateTime.Now.Day) {
g.DrawString(string.Format("{0}", i), new Font("Arial", 7), brush_red, (float)wLens * i + iX - 4.5f, iH);
} else {
g.DrawString(string.Format("{0}", i), new Font("Arial", 7), brush, (float)wLens * i + iX - 4.5f, iH);
}
g.DrawLine(oSpen, wLens * (i + 1) + iX, iH, wLens * (i + 1) + iX, iX);//画长线
}
#endregion #region 画纵坐标
//画纵坐标
for (int i = 0; i < fCount; i++) {
if (i != 0) {
g.DrawString(string.Format("{0}", fVirtualHeight - fRmb * i), new Font("Arial", 7), brush, (float)iX - 20.5f, i * fPx - 5);
}
g.DrawLine(oSpen, iX, i * fPx + iX, iW, i * fPx + iX);//长线
}
#endregion #region 生成点列
//生成点列
PointF[] oPoint = new PointF[oFloat.Length];
for (int i = 0; i < oFloat.Length; i++) {
//记录坐标
oPoint[i] = new PointF(i * wLens + iX, iH - oFloat[i] * fPPx); //输出标识
if (isText && oFloat[i] > 0) {
g.DrawString(string.Format("{0}", oFloat[i]), new Font("Arial", 8), brush, oPoint[i]);
}
}
#endregion
g.DrawLines(oRpen, oPoint);
//g.DrawCurve(oRpen, oPoint); //生成图片
oBmap.Save(path, ImageFormat.Gif); oBmap.Dispose();
g.Dispose();
return string.Empty;
}
#endregion
public static string DrawImage(float[] oFloat, bool isText,string path) {
#region 数值
int width = 660; //图片宽度
int height = 220; //图片高度
int iX = 20; //左,下方向留白
int iH = height - 20; //显示区域高度
int iW = width - 20; //显示区域宽度 float fHeight = 200; //纵轴总长度
float fVirtualHeight = fHeight; //虚拟总长度
//算出最大的正整数,如输入300,则最大数为400
float fTempMaxNum = MaxFloat(oFloat);
while (fVirtualHeight < fTempMaxNum) {
fVirtualHeight += 100;
}
float fCount = 10; //纵轴分成10份,固定
float fPx = fHeight / fCount; //每份多少像素,固定
float fRmb = fVirtualHeight / fCount; //每份表示多少钱,根据参数中最大数决定
float fPPx = fPx / fRmb; //每钱多少像素,
#endregion #region 构造图用
//构造BITMAP
Bitmap oBmap = new Bitmap(width, height); //新建一个画板
Graphics g = Graphics.FromImage(oBmap);
//设置高质量插值法
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
//设置高质量,低速度呈现平滑程度
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; //清空画布并以透明背景色填充
g.Clear(Color.White); //新建钢笔,灰色,1px
Pen oPen = new Pen(Color.Gray);
Pen oSpen = new Pen(Color.Silver);
Pen oRpen = new Pen(Color.Red); //定义黑色过渡型笔刷
LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, oBmap.Width, oBmap.Height), Color.Black, Color.Black, 1.2F, true);
LinearGradientBrush brush_red = new LinearGradientBrush(new Rectangle(0, 0, oBmap.Width, oBmap.Height), Color.Red, Color.Red, 1.2F, true); #endregion //计算宽度,高度份数
float wLens = iW / oFloat.Length; #region 画横纵坐标
//线帽
oPen.EndCap = LineCap.ArrowAnchor;
//画横纵坐标
g.DrawLine(oPen, iX, iH, iX, iX - 10);
g.DrawString("y", new Font("Arial", 8), brush, 25, 1);
g.DrawLine(oPen, iX, iH, iW + 10, iH);
g.DrawString("x", new Font("Arial", 8), brush, iW + 10, iH - 1);
//输出标题
//g.DrawString(string.Format("CreateDate {0}", DateTime.Now.ToString()), new Font("Arial", 8), brush, iW / 2, 1);
#endregion #region 画横坐标
//画横坐标
for (int i = 0; i < oFloat.Length; i++) {
//输出小竖线
if (i == DateTime.Now.Day) {
g.DrawString(string.Format("{0}", i), new Font("Arial", 7), brush_red, (float)wLens * i + iX - 4.5f, iH);
} else {
g.DrawString(string.Format("{0}", i), new Font("Arial", 7), brush, (float)wLens * i + iX - 4.5f, iH);
}
g.DrawLine(oSpen, wLens * (i + 1) + iX, iH, wLens * (i + 1) + iX, iX);//画长线
}
#endregion #region 画纵坐标
//画纵坐标
for (int i = 0; i < fCount; i++) {
if (i != 0) {
g.DrawString(string.Format("{0}", fVirtualHeight - fRmb * i), new Font("Arial", 7), brush, (float)iX - 20.5f, i * fPx - 5);
}
g.DrawLine(oSpen, iX, i * fPx + iX, iW, i * fPx + iX);//长线
}
#endregion #region 生成点列
//生成点列
PointF[] oPoint = new PointF[oFloat.Length];
for (int i = 0; i < oFloat.Length; i++) {
//记录坐标
oPoint[i] = new PointF(i * wLens + iX, iH - oFloat[i] * fPPx); //输出标识
if (isText && oFloat[i] > 0) {
g.DrawString(string.Format("{0}", oFloat[i]), new Font("Arial", 8), brush, oPoint[i]);
}
}
#endregion
g.DrawLines(oRpen, oPoint);
//g.DrawCurve(oRpen, oPoint); //生成图片
oBmap.Save(path, ImageFormat.Gif); oBmap.Dispose();
g.Dispose();
return string.Empty;
}
#endregion
解决方案 »
- 『100分』C#连接Access数据偶尔出错 求建立连接时完整的connString格式
- C# WinForm 读取 tif 格式图片问题。
- C#操作word文档,网word模版的域里面填充数据该怎么做!!
- c#好入门?也许,不过c#很一个很灵活的tool,能有效减少代码。
- 这个功能如何实现
- 如何使用C#做动画?
- vss2005怎么连接oracle数据库啊.
- 请问这里如何写统计数据的语句
- 怎么将十进制数转换为二进制数
- 芝麻开门,你上次教的undo和redo的办法还有点小问题。。。
- 关于C#嵌套类的问题,请帮我看看是否符合编程原则?
- Forms.UserContrl WindowsFormsHost 鼠标消息
先把图片地址粘进去,选中该地址,点击上边的插入图片,粘入,OK
再不行参数下边的写法自己写(注意没有空格)[ i m g = 图 片 地 址 ] 图 片 地 址 [ / i m g ]