0

我有一个 WPF 应用程序。该应用程序中嵌入了 2 个网页。当我截取屏幕截图时,我得到了除嵌入式网页之外的整个应用程序。

我需要截图,包括网页。有人可以指导我吗..

谢谢

4

2 回答 2

0

您可以尝试使用此代码

/// Gets a JPG "screenshot" of the current UIElement
    ///
    /// UIElement to screenshot
    /// Scale to render the screenshot
    /// JPG Quality
    /// Byte array of JPG data
    public static byte[] GetJpgImage(this UIElement source, double scale, int quality)
    {
        double actualHeight = source.RenderSize.Height;
        double actualWidth = source.RenderSize.Width;

        double renderHeight = actualHeight * scale;
        double renderWidth = actualWidth * scale;

        RenderTargetBitmap renderTarget = new RenderTargetBitmap((int) renderWidth, (int) renderHeight, 96, 96, PixelFormats.Pbgra32);
        VisualBrush sourceBrush = new VisualBrush(source);

        DrawingVisual drawingVisual = new DrawingVisual();
        DrawingContext drawingContext = drawingVisual.RenderOpen();

        using (drawingContext)
        {
            drawingContext.PushTransform(new ScaleTransform(scale, scale));
            drawingContext.DrawRectangle(sourceBrush, null, new Rect(new Point(0, 0), new Point(actualWidth, actualHeight)));
        }
        renderTarget.Render(drawingVisual);

        JpegBitmapEncoder jpgEncoder = new JpegBitmapEncoder();
        jpgEncoder.QualityLevel = quality;
        jpgEncoder.Frames.Add(BitmapFrame.Create(renderTarget));

        Byte[] _imageArray;

        using (MemoryStream outputStream = new MemoryStream())
        {
            jpgEncoder.Save(outputStream);
            _imageArray = outputStream.ToArray();
        }

        return _imageArray;
    }
于 2012-09-25T18:03:05.693 回答
0
try
    {
      // System.Drawing.Point p=new System.Drawing.Point(100,500);
        Bitmap b = new Bitmap(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height);
        Graphics graphics=Graphics.FromImage(b as Image);
        graphics.CopyFromScreen(0,0,0,0,b.Size);

       string stringsFile=@"C:\Image1";

        b.Save(stringsFile,ImageFormat.Png);
     }
  catch (Exception exp)
      {
      Microsoft.Windows.Controls.MessageBox.Show("Opps !!! " + exp.Message);
      } 
于 2012-09-25T17:36:29.260 回答