读书人

该如何使用asp.net画出正弦曲线呢

发布时间: 2013-09-16 13:45:21 作者: rapoo

该怎么使用asp.net画出正弦曲线呢
改怎么样使用asp.net画出正弦曲线呢,求大神求思路 ASP.NET
[解决办法]

 try
{
using (Bitmap sinImage = new Bitmap(360, 120))
{

using (Graphics myGraphics = Graphics.FromImage(sinImage))
{

myGraphics.Clear(Color.White);
myGraphics.SmoothingMode = SmoothingMode.AntiAlias;
Rectangle r1 = new Rectangle(0, 0, 360, 20);
Rectangle r2 = new Rectangle(0, 20, 360, 40);
Rectangle r3 = new Rectangle(0, 60, 360, 40);
Rectangle r4 = new Rectangle(0, 100, 360, 20);

Brush brush1 = new SolidBrush(Color.White);
Brush brush2 = new SolidBrush(Color.SkyBlue);
Brush brush3 = new SolidBrush(Color.Pink);
Brush brush4 = new SolidBrush(Color.YellowGreen);



myGraphics.FillRectangle(brush1, r1);
myGraphics.FillRectangle(brush2, r2);
myGraphics.FillRectangle(brush2, r3);
myGraphics.FillRectangle(brush1, r4);

myGraphics.DrawString("0", new Font("宋体", 8), brush1, new PointF(3, 65));
myGraphics.DrawString("90", new Font("宋体", 8), brush1, new PointF(85, 65));
myGraphics.DrawString("180", new Font("宋体", 8), brush1, new PointF(170, 65));
myGraphics.DrawString("360", new Font("宋体", 8), brush1, new PointF(336, 65));

Point myPoint = new Point(0, 60);
float sinValue = 0.0F;
for (int i = 0; i < 360; i++)
{
sinValue = Convert.ToSingle(Math.Sin(Convert.ToSingle((i * Math.PI) / 180))) * 40;

//事实上,这里根本无需注意 sinValue 的正负
//当其为负时, 60-sinValue 则会变大
Point thisPoint = new Point(i, Convert.ToInt32(60 - sinValue));


myGraphics.DrawLine(new Pen(brush3), thisPoint, myPoint);
myPoint = thisPoint;
}
}
using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
{
System.Web.HttpContext.Current.Response.ContentType = "Image/PNG";
System.Web.HttpContext.Current.Response.Clear();
System.Web.HttpContext.Current.Response.BufferOutput = true;
sinImage.Save(ms, ImageFormat.Png);
ms.Flush();
System.Web.HttpContext.Current.Response.BinaryWrite(ms.GetBuffer());
}
}
}
catch
{
return;
}

}

读书人网 >.NET

热点推荐