从比屏幕高的控件绘制位图
我在将 C# 控件保存到位图文件时遇到很多问题。所讨论的控件是一种绘图表面,用户可以在其上书写文本、绘制图片和绘制框。该控件可调整大小并可拖动。发生的情况是,当控件非常大并且在屏幕上不完全可见时,控件不可见的部分会在位图上保存为半绘制状态。用于生成位图的代码非常简单:
Bitmap bitmap = new Bitmap(myControl.Width, myControl.Height);
myControl.DrawToBitmap(bitmap);
我尝试了以下方法来尝试获得完全绘制的位图,但没有成功:
myControl.Invalidate(myControl.ClientRectangle, true);
myControl.Refresh();
myControl.Update();
Application.DoEvents();
我无法缩小控件以使其完全可见,因为分辨率和图像质量对于那个项目。事实上,我实际上正在尝试放大图像以提高其质量。有没有什么方法我不知道从控件生成图像?
坦克你。
I am having quite a few problems saving a C# control to a bitmap file. The control in question is a kind of drawing surface on which the user can write text, draw pictures and paint boxes. The control is resizable and draggable. What happen is, when the control is really big and is not totally visible on the screen, the parts of the control not visible are saved half-drawn on the bitmap. The code used to generate the bitmap is quite simple:
Bitmap bitmap = new Bitmap(myControl.Width, myControl.Height);
myControl.DrawToBitmap(bitmap);
I have tried the following methods to try to have a fully painted bitmap, without any success:
myControl.Invalidate(myControl.ClientRectangle, true);
myControl.Refresh();
myControl.Update();
Application.DoEvents();
I cannot scale the control down to make it fully visible since resolution and image quality are very important for that project. In fact, I am actually trying to scale the image up to increase it's quality. Are there ways I am not aware of generating an image from a control ?
Tank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
DrawToBitmap
有局限性,并不总是按预期工作。尝试使用本机GDI+这里是示例
DrawToBitmap
has limitations and dont always work as expected. Try instead work with native GDI+Here is example
也许我的答案在这里 捕获隐藏或最小化的窗口可以帮助你吗?
Maybe my answer here Capturing a Window that is hidden or minimized can help you?