一个数据流转化成一个图片保存起来...大家帮忙看看.急急.
这个小例子在ASP.NET上画图出了一个图形,怎样把这个图形保存为图片显示在Image 或ImageButton控件中.
代码:
---------------------
const int with =600,height =400;
Bitmap mypalette = new Bitmap(with,height);
Graphics myGraphics = Graphics.FromImage(mypalette);
//绘制白色背景
myGraphics.FillRectangle(new SolidBrush(Color.Black),0,0,with,height);
//设定显示数据
string[] DataName ={"lichun","fer","apr","may","jun"};
int[] MembData = {1000,2000,800,948,1500};
int[] Data ={100,50,6,13,65};
for(int i=0;i<MembData.Length;i++)
{
Data[i] = MembData[i]/10;
}
//设定显示色
Color[] mycolor ={Color.Blue,Color.Red,Color.Yellow,Color.Orange,Color.Purple};
myGraphics.DrawString("公司员工月薪情况",new Font("黑体",30),Brushes.White,new PointF(0,0));
//绘画柱图
for(int i =0;i<DataName.Length;i++)
{
//填充柱图
myGraphics.FillRectangle(new SolidBrush(mycolor[i]),(i*40)+30,300-Data[i],20,Data[i]);
//绘制柱图边界
myGraphics.DrawRectangle(new Pen(Color.Black),(i*40)+40,30-Data[i],20,Data[i]);
//绘制柱图上方的数据
myGraphics.DrawString(MembData[i].ToString() + "元",new Font("宋体",9),Brushes.Wheat,new PointF((i*40)+30,300-Data[i]-20));
//绘制柱图下标
myGraphics.DrawString(DataName[i],new Font("宋体",9),Brushes.White ,new PointF((i*40)+30,310));
}
mypalette.Save(Response.OutputStream,ImageFormat.Jpeg);
问题点数:10、回复次数:2Top
1 楼tidydavid(tidy)回复于 2006-03-04 21:17:54 得分 10
单独做一个aspx的页面,这个页面功能是:生成图片把流直接送到客户端。
然后把要显示图片的控件的来源设置成刚才做的aspx页面就行了。Top
2 楼lirongchun1313(sfsdfsdf)回复于 2006-03-05 13:12:22 得分 0
谢谢.Top




