Rendering form to bitmap

2019-01-20 13:11发布

I would like to render Form to bitmap... Is it possible in .net 2.0?

1条回答
我只想做你的唯一
2楼-- · 2019-01-20 13:25

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");
    }
}
查看更多
登录 后发表回答