public Bitmap CreateBitmap()
{
Response.ContentType="image/jpeg";
Bitmap bitmap=new Bitmap(100,30);
Graphics graphics =Graphics.FromImage(bitmap);
Random random =new Random();
for(int i =0;i<30;i++)
{
int x1 = random.Next(100);
int x2 =random.Next(100);
int y1 =random.Next(30);
int y2 = random.Next(30);
graphics.DrawLine(new Pen(Color.Black,1), new Point(x1,y1),new Point(x2,y2));
}
graphics.Flush();
return bitmap;
}
调用段:
Bitmap bitmap= CreateBitmap();
bitmap.Save(Response.OutputStream,ImageFormat.Jpeg);