如何在Windows应用程序中将表单内容转换为图像 [英] How convert the form content to image in windows application

查看:90
本文介绍了如何在Windows应用程序中将表单内容转换为图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


如何在Windows应用程序中将表单内容转换为图像?

Hi
How to convert the form content to image in windows application?

推荐答案

在这里,您可以...保持表单在屏幕上可见. 矩形对象是表单相对于屏幕的矩形区域.然后可以保存位图.

Here you go... keep the form visible on the screen..
Rectangle object is the rectangle area of the form with respect to screen. You can save the Bitmap then.

private Bitmap CaptureImage(Control wnd, Rectangle rc)
{
	Bitmap result;
	if (rc.Width > 0 && rc.Height > 0)
	{
		Bitmap bitmap = null;
		Image[] array = new Bitmap[1];
		using (Graphics graphics = wnd.CreateGraphics())
		{
			bitmap = new Bitmap(rc.Width, rc.Height, graphics);
			using (Graphics graphics2 = Graphics.FromImage(bitmap))
			{
				graphics2.CopyFromScreen(rc.X, rc.Y, 0, 0, rc.Size, CopyPixelOperation.SourceCopy);
			}
		}
		array[0] = bitmap;
		result = bitmap;
	}
	else
	{
		result = null;
	}
	return result;
}


除了Vivek的解决方案:

如何获得覆盖所有表格的矩形?使用Control.PointToScreen:

In addition to the solution by Vivek:

How to get the Rectangle which covers all the Form? Use Control.PointToScreen:

class MyForm : Form {
    //...
    Rectangle FormToScreen() {
        return new Rectangle(
            this.PointToScreen(new Point(0, 0)),
            new Size(this.Width, this.Height));
    }
}



—SA



—SA


这篇关于如何在Windows应用程序中将表单内容转换为图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆