C# 打印屏幕滚动控件

发布于 2024-10-26 21:02:42 字数 1165 浏览 0 评论 0原文

我有一个控件,它是可滚动的绘图仪。绘图仪完成绘图后,可以像这样滚动: 在此处输入图像描述

我的绘图仪是实时绘图仪,即它会随着时间的推移进行绘图,而不是静态绘图仪(您手动输入值的一个)。停止绘图仪后,我可以滚动绘图仪以查看结果。但是,我想将绘图仪保存到图像中,我正在尝试使用打印屏幕方法来完成此操作。但我能够捕获的只是绘图仪的可见部分,而不是绘图仪的不可见部分(这是因为它需要滚动)。我希望现在更清楚了。 打印屏幕的代码是:

// Set the bitmap object to the size of the screen
        bmpScreenshot = new Bitmap(panel2.Bounds.Width, panel2.Bounds.Height, PixelFormat.Format32bppArgb);
        // Create a graphics object from the bitmap
        gfxScreenshot = Graphics.FromImage(bmpScreenshot);

        Point p = this.PointToScreen(new Point(panel2.Bounds.X, panel2.Bounds.Y));
        gfxScreenshot.CopyFromScreen(p.X, p.Y, 0, 0,
                         panel2.Bounds.Size, CopyPixelOperation.SourceCopy);


        SaveFileDialog saveImageDialog = new SaveFileDialog();
        saveImageDialog.Title = "Select output file:";
        saveImageDialog.Filter = "JPeg Image|*.jpg|Bitmap Image|*.bmp|Gif Image|*.gif";
        if (saveImageDialog.ShowDialog() == DialogResult.OK)
        {
            bmpScreenshot.Save(saveImageDialog.FileName, ImageFormat.Jpeg);
        }

非常感谢。

i have a control that is the plotter which is scrollable. After the plotter has finished plotting, it is able to scroll just like this:
enter image description here

My plotter is a real-time plotter i.e. meaning it plots as time goes by and it's not a static plotter(one which u put in the values manually). After I've stopped the plotter, I'm able to scroll around the plotter to see the results. However, I want to save the plotter into an image, which I'm trying to do using print screen method. But what I was able to capture is only the visible part of the plotter, but not the non-visible part of the plotter(which is because it needs scrolling). I hope it's clearer now.
The code for the print screen is:

// Set the bitmap object to the size of the screen
        bmpScreenshot = new Bitmap(panel2.Bounds.Width, panel2.Bounds.Height, PixelFormat.Format32bppArgb);
        // Create a graphics object from the bitmap
        gfxScreenshot = Graphics.FromImage(bmpScreenshot);

        Point p = this.PointToScreen(new Point(panel2.Bounds.X, panel2.Bounds.Y));
        gfxScreenshot.CopyFromScreen(p.X, p.Y, 0, 0,
                         panel2.Bounds.Size, CopyPixelOperation.SourceCopy);


        SaveFileDialog saveImageDialog = new SaveFileDialog();
        saveImageDialog.Title = "Select output file:";
        saveImageDialog.Filter = "JPeg Image|*.jpg|Bitmap Image|*.bmp|Gif Image|*.gif";
        if (saveImageDialog.ShowDialog() == DialogResult.OK)
        {
            bmpScreenshot.Save(saveImageDialog.FileName, ImageFormat.Jpeg);
        }

Thanks a lot.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

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