0
我有一個WPF應用程序。該應用程序中嵌入了2個網頁。當我截取屏幕截圖時,除了嵌入式網頁外,我獲得了整個應用程序。如何使用WebPage嵌入WPF屏幕截圖
我需要截圖包括網頁。有人可以請指導我..
感謝
我有一個WPF應用程序。該應用程序中嵌入了2個網頁。當我截取屏幕截圖時,除了嵌入式網頁外,我獲得了整個應用程序。如何使用WebPage嵌入WPF屏幕截圖
我需要截圖包括網頁。有人可以請指導我..
感謝
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 [email protected]"C:\Image1";
b.Save(stringsFile,ImageFormat.Png);
}
catch (Exception exp)
{
Microsoft.Windows.Controls.MessageBox.Show("Opps !!! " + exp.Message);
}
您可以使用此代碼
/// 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;
}
這不起作用,屏幕的網頁的部分當屬空白嘗試。 – Vinay