refs:
http://stackoverflow.com/questions/2851236/rendertargetbitmap-resourced-visualbrush-incomplete-image#
private static RenderTargetBitmap CreateBitmapSource(FrameworkElement frameElement)
{
// Temporarily add a PresentationSource if none exists
var temporaryPresentationSource = new HwndSource(new HwndSourceParameters())
{
RootVisual = (VisualTreeHelper.GetParent(frameElement) == null ? frameElement : null)
};
using (temporaryPresentationSource)
{
// Flush the dispatcher queue
System.Windows.Application.Current.Dispatcher.Invoke(DispatcherPriority.SystemIdle, new Action(() => { }));
// Render to bitmap
var rtb = new RenderTargetBitmap((int)frameElement.ActualWidth, (int)frameElement.ActualHeight, 96, 96, PixelFormats.Pbgra32);
rtb.Render(frameElement);
return rtb;
}
}