现在的位置: 首页 > 综合 > 正文

c# 将控件保存为图片

2012年03月29日 ⁄ 综合 ⁄ 共 1063字 ⁄ 字号 评论关闭

Bitmap NewBitmap = new Bitmap(panel1.Width, panel1.Height);

                panel1.DrawToBitmap(NewBitmap, new Rectangle(0, 0,NewBitmap.Width, NewBitmap.Height));

               NewBitmap.Save(Application.StartupPath + @"..\Picture\LayOut\xx.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);

     // MessageBox.Show(Application.StartupPath + @"\Picture\LayOut\xx.jpg");
            NewBitmap.Dispose();

private void Page_Load(object sender, System.EventArgs e)
{
if ( !IsPostBack ){

Bitmap newBitmap = new Bitmap(36,16,PixelFormat.Format32bppArgb);
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(newBitmap);
g.FillRectangle(new SolidBrush(Color.White),new Rectangle(0,0,36,16));
System.Drawing.Font textFont = new Font("Times new Roman",10);
System.Drawing.RectangleF rectangle = new RectangleF(0,0,36,16);
Random rd = new Random();
int valationNo = rd.Next(1000,8999);
g.FillRectangle(new SolidBrush(Color.BurlyWood),rectangle);
g.DrawString(valationNo.ToString(),textFont,new SolidBrush(Color.Blue),rectangle);
newBitmap.Save(Server.MapPath("img")+"\\19.gif",ImageFormat.Gif);

g.Dispose();//记得释放资源
newBitmap.Dispose();
}
}  

抱歉!评论已关闭.