将表单渲染为位图 [英] Rendering form to bitmap
本文介绍了将表单渲染为位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将 Form 渲染为位图...在 .net 2.0 中可以吗?
I would like to render Form to bitmap... Is it possible in .net 2.0?
推荐答案
当然,您可以调用 Control.DrawToBitmap()
将控件呈现为位图.对于更一般的绘图,您可以创建一个 Bitmap
,然后使用 Graphics.FromImage()
创建一个 Graphics
实例.然后,您可以照常绘制到此图形实例.
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.
这是一个可以自己绘制的简单表单(只需添加一个按钮并双击它即可添加 Click 事件处理程序:
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");
}
}
这篇关于将表单渲染为位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文