Jeremy Alles
unread,Apr 6, 2011, 3:59:18 AM4/6/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to wpf-di...@googlegroups.com
Hi everybody,
I'm working on a WPF diagramming control and I need to have a drag/drop feature with some kind of "ghost" support. When the user starts dragging the current selection, I must display a ghost of the selected objects right under the mouse cursor. I've this feature working since a few weeks and now I'm starting to look at performance.
I'm using the following code to take a snapshot of my control and then I crop it to fit the current selection. This code sample is very popular on the web:
public static BitmapSource CaptureVisual(Visual target, double dpiX, double dpiY)
{
Rect bounds = VisualTreeHelper.GetDescendantBounds(target);
RenderTargetBitmap rtb = new RenderTargetBitmap((int)(bounds.Width * dpiX / 96.0),
(int)(bounds.Height * dpiY / 96.0),
dpiX,
dpiY,
PixelFormats.Pbgra32);
DrawingVisual drawingVisual = new DrawingVisual();
using (DrawingContext context = drawingVisual.RenderOpen())
{
VisualBrush visualBrush = new VisualBrush(target);
context.DrawRectangle(visualBrush, null, new Rect(new Point(), bounds.Size));
}
rtb.Render(drawingVisual);
return rtb;
}
I'm looking for other implementation which could have better performance. In particular when my control starts being big, the rtb.Render call takes a lot of time.
Do you have any idea ?
Regards,
Jeremy