[Bash shell] 纯文本查看 复制代码
protected void Page_Load(object sender, EventArgs e)
{
this.CreateImage();
this.Cutpicture();
}
private void CreateImage()
{
//string district = Session["District"].ToString();
//string channel = Session["Channel"].ToString();
//string timeselect = Session["TimeSelect"].ToString();
//string indicator = Session["Indicator"].ToString();
// string title = ""+channel.ToString()+""+""+indicator.ToString()+""+"统计图";
//定义所画图形的大小
int height = 400, width = 540;
Bitmap bitmap = new Bitmap(width, height);
Graphics g = Graphics.FromImage(bitmap);
//定义一些字体
g.Clear(Color.White);
Font font = new System.Drawing.Font("Arial", 5, FontStyle.Regular);
Font font1 = new System.Drawing.Font("宋体", 20, FontStyle.Regular);
Font font2 = new System.Drawing.Font("Arial", 10, FontStyle.Regular);
//画背景色
LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0,0,bitmap.Width,bitmap.Height), Color.Blue, Color.Blue, 1.2f, true);
g.FillRectangle(Brushes.AliceBlue, 0, 0, width, height);
Brush brush1 = new SolidBrush(Color.Blue);
Brush brush2 = new SolidBrush(Color.SaddleBrown);
//字体显示位置
g.DrawString("hah", font1, brush1, new PointF(100, 30));
//画图片的边框线(最外头的矩形框)
g.DrawRectangle(new Pen(Color.Blue), 0, 0, bitmap.Width-1,bitmap.Height-1);
Pen mypen = new Pen(brush, 1);
Pen mypen2 = new Pen(Color.Red, 2);
//绘制线条
//绘制纵向线条
int x = 45;
for (int i = 0; i < 24; i++)
{
g.DrawLine(mypen, x, 80, x, 350);
x = x + 20;
}
Pen mypen1 = new Pen(Color.Blue, 2);
g.DrawLine(mypen1, x - 480, 80, x - 480, 350);
//绘制横向线条
int y = 100;
for (int i = 0; i < 5; i++)
{
g.DrawLine(mypen, 45, y, 530, y);
y = y + 50;
}
g.DrawLine(mypen1, 45, y, 530, y);
//x轴
string[] n = { "00:00\n-1:00\n", "1:00\n-2:00\n", "2:00\n-3:00\n", "3:00\n-4:00\n", "4:00\n-5:00\n", "5:00\n-6:00\n", "6:00\n-7:00\n", "7:00\n-8:00\n", "8:00\n-9:00\n", "9:00\n-10:00\n", "10:00\n-11:00\n", "11:00\n-12:00\n", "12:00\n-13:00\n", "13:00\n-14:00\n", "14:00\n-15:00\n", "15:00\n-16:00\n", "16:00\n-17:00\n", "17:00\n-18:00\n", "18:00\n-19:00\n", "19:00\n-20:00\n", "20:00\n-21:00\n", "21:00\n-22:00\n", "22:00\n-23:00\n", "23:00\n-00:00\n" };
x = 45;
for (int i = 0; i < 24; i++)
{
g.DrawString(n[i].ToString(), font, Brushes.Red, x, 355);
x = x + 20;
}
//y轴
string[] m = {"2.5", "2", "1.5", "1", "0.5", "0"};
y = 90;
for (int i = 0; i < 6; i++)
{
g.DrawString(m[i].ToString(), font2, Brushes.Red, 15, y);
y = y + 50;
}
PRealData pRealData = new PRealData();
string str = "select* from RealTimeData";
string num = "select UserName from Customer";
int CustomerSum = pRealData.CustomerSum(num);
int[] PerChannPday = new int[24];
// int[] PerHourSum = new int[24];
int[] Count1 = new int[24];
PerChannPday = pRealData.PerChannPDay(str,"CCTV-1");
// PerHourSum = pRealData.PerHourSum(str);
for (int i = 0; i < 24; i++)
{
Count1[i] = PerChannPday[i]*1000/(60 * CustomerSum);
}
// GridView1.DataSource = Count1;
// GridView1.DataBind();
SolidBrush mybrush = new SolidBrush(Color.Red);
Point[] points1 = new Point[24];
points1[0].X = 45; points1[0].Y = 350 - Count1[0];
points1[1].X = 65; points1[1].Y = 350 - Count1[1];
points1[2].X = 85; points1[2].Y = 350 - Count1[2];
points1[3].X = 105; points1[3].Y = 350 - Count1[3];
points1[4].X = 125; points1[4].Y = 350 - Count1[4];
points1[5].X = 145; points1[5].Y = 350 - Count1[5];
points1[6].X = 165; points1[6].Y = 350 - Count1[6];
points1[7].X = 185; points1[7].Y = 350 - Count1[7];
points1[8].X = 205; points1[8].Y = 350 - Count1[8];
points1[9].X = 225; points1[9].Y = 350 - Count1[9];
points1[10].X = 245; points1[10].Y = 350 - Count1[10];
points1[11].X = 265; points1[11].Y = 350 - Count1[11];
points1[12].X = 285; points1[12].Y = 350 - Count1[12];
points1[13].X = 305; points1[13].Y = 350 - Count1[13];
points1[14].X = 325; points1[14].Y = 350 - Count1[14];
points1[15].X = 345; points1[15].Y = 350 - Count1[15];
points1[16].X = 365; points1[16].Y = 350 - Count1[16];
points1[17].X = 385; points1[17].Y = 350 - Count1[17];
points1[18].X = 405; points1[18].Y = 350 - Count1[18];
points1[19].X = 425; points1[19].Y = 350 - Count1[19];
points1[20].X = 445; points1[20].Y = 350 - Count1[20];
points1[21].X = 465; points1[21].Y = 350 - Count1[21];
points1[22].X = 485; points1[22].Y = 350 - Count1[22];
points1[23].X = 505; points1[23].Y = 350 - Count1[23];
g.DrawLines(mypen2, points1); //绘制折线
System.IO.MemoryStream ms = new System.IO.MemoryStream();
bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
Response.ClearContent();
Response.ContentType = "image/Jpeg";
Response.BinaryWrite(ms.ToArray());
}
private void Cutpicture()
{
Rectangle R = System.Windows.Forms.Screen.PrimaryScreen.Bounds;
R.Width = 540;
R.Height = 400;
System.Drawing.Image img = new Bitmap(R.Width, R.Height);
Graphics G = Graphics.FromImage(img);
G.CopyFromScreen(new Point(0,86), new Point(0, 0), new Size(R.Width, R.Height));
IntPtr dc = G.GetHdc();
G.ReleaseHdc(dc);
G.Dispose();
img.Save("c:\\a.jpg");
}