CopyFromScreen无法正常工作

时间:2012-05-04 12:04:29

标签: c#

这个有点令人困惑......

我正在使用Adobe的PDF Viewer控件来查看PDF,但我希望用户能够将图像拖到PDF上,然后当他们点击保存时,它会将图像添加到该位置的PDF。

实现PDF查看器证明非常困难,但我最终决定使用Adobe的控件,拍照,然后允许用户在PDF图片的顶部绘制图像。当他们点击保存时,我将使用PDFSharp将图像放到PDF上,一旦我找到它的位置,但我现在遇到的问题是我无法获得PDF的图片。

以下代码用于获取图片,但附加的面板只显示带有红色“X”和边框的白色背景......

using (Bitmap bitmap = new Bitmap(adobePDFViewer1.Width, adobePDFViewer1.Height))
                {
                    using (Graphics g = Graphics.FromImage(bitmap))
                    {
                        g.CopyFromScreen(new Point(adobePDFViewer1.Left, adobePDFViewer1.Top), Point.Empty, adobePDFViewer1.Size);
                    }
                    panelOverPdfViewer.BackgroundImage = bitmap;
                }

我不认为这是最好的方式,但我无法解决任何其他问题。任何帮助将不胜感激!

编辑:

下面是一个非常有用的答案,这是工作代码:

以下是我使用的代码:

Bitmap printscreen = new Bitmap(adobePDFViewer1.Width, adobePDFViewer1.Height);
                Graphics graphics = Graphics.FromImage(printscreen as Image);
                int left = this.Left + 396;
                int top = this.Top + 30;
                graphics.CopyFromScreen(left, top, 0, 0, printscreen.Size);
                pictureBoxOverPDFView.Image = printscreen;

1 个答案:

答案 0 :(得分:3)

请看这个Print-Screen

并尝试使用CopyFromScreen的测试工作

private void PrintScreen()

{  

Bitmap printscreen = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);

Graphics graphics = Graphics.FromImage(printscreen as Image);

graphics.CopyFromScreen(0, 0, 0, 0, printscreen.Size);

printscreen.Save(@"C:\Temp\printscreen.jpg", ImageFormat.Jpeg);

} 
相关问题