我怎么能在我的形式保存面板为图片? [英] How can I save a Panel in my form as a picture?

查看:205
本文介绍了我怎么能在我的形式保存面板为图片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有了2板的形式。我想是Panel2的内容保存为图像。我看见谈到使用屏幕捕获做这个线程,但我不能再找到线索。另请阅读有关使用DrawToBitMap方法,但它从Visual Studio 2005的信息是,不知道这是否是这个最新的或合适的解决方案。 ?所以,你有什么建议救了我是Panel2为图片,最好是JPG



更新:
我实现推荐下面的DrawToBitMap的代码,但它节省了一半的是Panel2的(左半边,如果有差别)。
,因为它救了我一半是Panel2,我用'2'乘以宽度呼尽其保存完整形式。一个奇怪的事情种类和没有意义对我来说,因为面板2的宽度应该是完整的液晶面板,而不是它的一半?



  //乘以2是Panel2调用的宽度,使其保存完整的面板
BMP位图=新位图(splitContainer1.Panel2.Width * 2,splitContainer1.Panel2.Height);
splitContainer1.Panel2.DrawToBitmap(BMP,splitContainer1.Panel2.Bounds);
bmp.Save(@C:\Test.bmp);


解决方案

Control.DrawToBitMap 仍。支持.NET 4有以下注意事项



从上面的链接:




  • 不支持ActiveX控件的方法DrawToBitmap。你
    可以覆盖OnPrint事件,并提供自定义打印逻辑,如果需要的话



DrawToBitmap方法有以下限制:




  • 一个ArgumentException可能会抛出大量位图。最高
    允许大小通过机而异。

  • DrawToBitmap不支持墨迹控件在Windows XP
    Tablet PC版2005操作系统。

  • 如果
    文本框的Visible属性设置为false DrawToBitmap不画小孩文本框。

  • 容器内部控制以相反的顺序呈现。

  • DrawToBitmap不是全功能的RichTextBox的;只有一个位图的
    绘制边框时



编辑添加的例子和图像:

  BMP位图=新位图(panel1.Width,panel1.Height); 
panel1.DrawToBitmap(BMP,panel1.Bounds);
bmp.Save(@C:\Temp\Test.bmp);




I have a form that has 2 panels. I'm trying to save the contents of Panel2 as an image. I saw a thread that talked about using the screen capture to do this, but I can't find the thread anymore. Also read about using the DrawToBitMap method, but it's from visual studio 2005 info, not sure if it's the most current or suitable solution for this. So what do you recommend for saving my Panel2 as a picture, preferably a jpg?

UPDATE: I implemented the code recommended below for the DrawToBitMap, but it saves half of my panel2 (the left half if that makes a difference). Because it saved half my panel2, I multiplied the width call by '2' to make it save the full form. Kind of a weird thing and doesn't make sense to me since the width of panel 2 should be the full panel and not half of it?

//multiplies the width of panel2 call by 2 to make it save the full panel
Bitmap bmp = new Bitmap(splitContainer1.Panel2.Width * 2, splitContainer1.Panel2.Height);
splitContainer1.Panel2.DrawToBitmap(bmp, splitContainer1.Panel2.Bounds);
bmp.Save(@"C:\Test.bmp");

解决方案

Control.DrawToBitMap is still supported in .Net 4. With the following caveats.

From above link:

  • The DrawToBitmap method is not supported for ActiveX controls. You can override the OnPrint event and provide custom printing logic if required.

The DrawToBitmap method has the following limitations:

  • An ArgumentException might be thrown for large bitmaps. The maximum allowable size varies by machine.
  • DrawToBitmap does not support the Ink controls for the Windows XP Tablet PC Edition 2005 operating system.
  • DrawToBitmap does not draw a child TextBox if the Visible property of the TextBox is set to false.
  • Controls inside containers are rendered in reverse order.
  • DrawToBitmap is not fully functional for the RichTextBox; only the border of a bitmap is drawn.

Edit Added example and image:

Bitmap bmp = new Bitmap(panel1.Width,panel1.Height);
panel1.DrawToBitmap(bmp, panel1.Bounds);
bmp.Save(@"C:\Temp\Test.bmp");

这篇关于我怎么能在我的形式保存面板为图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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