Get Bitmap Source
//http://simpledbbrowser.codeplex.com/
//License: Microsoft Public License (Ms-PL)
using System.Diagnostics;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace AWS.Framework.WPF.Utility
{
public sealed class Helpers
{
public static BitmapSource GetBitmapSource(FrameworkElement element)
{
DrawingVisual visual = new DrawingVisual();
DrawingContext context = visual.RenderOpen();
VisualBrush elementBrush = new VisualBrush(element);
int w = (int)element.ActualWidth;
int h = (int)element.ActualHeight;
context.DrawRectangle(elementBrush, null, new Rect(0, 0, w, h));
context.Close();
RenderTargetBitmap bitmap = new RenderTargetBitmap(w, h, 96, 96, PixelFormats.Default);
bitmap.Render(visual);
return bitmap;
}
}
}
Related examples in the same category