![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
| |
| | #1 (permalink) |
| | Render WPF Pages to Images Is there any way to render WPF pages to images, just like mem dc in GDI or Graphics(&Bitmap(...)) in GDI+ ? Thanks very much. |
My System Specs![]() |
| | #2 (permalink) |
| | RE: Render WPF Pages to Images You want to use a RenderTargetBitmap which takes any FrameworkElement...here is a code snippet: private Brush CreateBrushFromUIElementWithBitmap(UIElement element, BrushMappingMode viewboxUnits, Rect viewbox, BrushMappingMode viewportUnits, Rect viewport) { FrameworkElement fe = element as FrameworkElement; if (fe == null) return null; //Snap the current visual of "this" to a bitmap to be used in 3d animation RenderTargetBitmap bitmapImage = new RenderTargetBitmap((int)fe.ActualWidth, (int)fe.ActualHeight, 96, 96, PixelFormats.Pbgra32); bitmapImage.Render(element); ImageBrush imageBrush = new ImageBrush(); imageBrush.ImageSource = bitmapImage; imageBrush.ViewboxUnits = viewboxUnits; imageBrush.Viewbox = viewbox; imageBrush.ViewportUnits = viewportUnits; imageBrush.Viewport = viewport; return imageBrush as Brush; } If you want to save the image as a file, you can do something like this: _Encoder = new BmpBitmapEncoder(); RenderTargetBitmap bitmapImage = new RenderTargetBitmap((int)this.ActualWidth, (int)this.ActualHeight, 96, 96, PixelFormats.Pbgra32); bitmapImage.Render(element); _Encoder.Frames.Add(BitmapFrame.Create(bitmapImage)); FileStream stream = new FileStream(_Path, FileMode.Create); _Encoder.Save(stream); stream.Flush(); stream.Close(); "liubin.net@gmail.com" wrote: > Is there any way to render WPF pages to images, just like mem dc in GDI > or Graphics(&Bitmap(...)) in GDI+ ? > > Thanks very much. > > |
My System Specs![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| render xml page | .NET General | |||
| CS1.6 can only run as software render under vista RC1? | Vista Games | |||