I would like to render Form to bitmap... Is it possible in .net 2.0?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Sure, you can call Control.DrawToBitmap()
to render a control to a bitmap. For more general drawing, you can create a Bitmap
and then use Graphics.FromImage()
to create a Graphics
instance. You can then draw to this graphics instance as normal.
Here's a simple form that can draw itself (just add a button and double click it to add the Click event handler:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Bitmap b = new Bitmap(Width, Height);
DrawToBitmap(b, new Rectangle(0, 0, Width, Height));
b.Save("Test.bmp");
}
}