我有一个WPF应用程序。该应用程序中嵌入了2个网页。当我拍摄截图时,除了嵌入式网页之外,我得到整个应用程序。
我需要截取包括网页在内的截图。有人可以指导我..
由于
答案 0 :(得分: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);
}
答案 1 :(得分: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;
}