从比屏幕高的控件绘制位图

发布于 2024-10-22 02:06:54 字数 540 浏览 2 评论 0原文

我在将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清风挽心 2024-10-29 02:06:54

DrawToBitmap 有局限性,并不总是按预期工作。尝试使用本机GDI+

这里是示例

DrawToBitmap has limitations and dont always work as expected. Try instead work with native GDI+

Here is example

森林散布 2024-10-29 02:06:54

也许我的答案在这里 捕获隐藏或最小化的窗口可以帮助你吗?

Maybe my answer here Capturing a Window that is hidden or minimized can help you?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文