Скриншот с WPF WebBrowser

public static string GetThumbnailImage(WebBrowser CurrentBrowser) { Guid guid = Guid.NewGuid(); string ThumbnailPath = guid.ToString() + ".png"; Image imgScreen = new Image(); imgScreen.Width = 120; imgScreen.Height = 100; imgScreen.Source = new DrawingImage(VisualTreeHelper.GetDrawing(CurrentBrowser)); FileStream stream = new FileStream(ThumbnailPath, FileMode.Create); DrawingVisual vis = new DrawingVisual(); DrawingContext cont = vis.RenderOpen(); cont.DrawImage(imgScreen.Source, new Rect(new Size(120d, 100d))); cont.Close(); RenderTargetBitmap rtb = new RenderTargetBitmap((int)imgScreen.Width, (int)imgScreen.Height, 96d, 96d, PixelFormats.Default); rtb.Render(vis); PngBitmapEncoder encoder = new PngBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(rtb)); encoder.Save(stream); stream.Close(); return ThumbnailPath; } ...

September 15, 2012 · 1 мин · ksemenenko

Как сделать скриншот с WPF контрола

public void SaveImage(Visual visual, string filePath) { Rect bounds = VisualTreeHelper.GetDescendantBounds(visual); RenderTargetBitmap bitmap = new RenderTargetBitmap((Int32)bounds.Width, (Int32)bounds.Height, 96, 96, PixelFormats.Pbgra32); bitmap.Render(visual); PngBitmapEncoder image = new PngBitmapEncoder(); image.Frames.Add(BitmapFrame.Create(bitmap)); using (Stream fs = File.Create(filePath)) { image.Save(fs); } } ...

September 14, 2012 · 1 мин · ksemenenko