rendertargetbitmap

Oct 16, 2011 at 12:07 PM

I am trying to render a part of my visual tree containing an image with a shader. The entire tree renders except for the image with the shader. When I remove the shader, the image renders ok. I use the following to render:

public static RenderTargetBitmap GenerateBitmap(FrameworkElement element)

       {

           System.Windows.Size size = new System.Windows.Size(element.ActualWidth, element.ActualHeight);

           element.Measure(size);

           element.Arrange(new Rect(size));

           element.UpdateLayout();

           element.ApplyTemplate();

          RenderTargetBitmap bmpCopied = new RenderTargetBitmap((int)(size.Width),

                                                   (int)(size.Height ),

                                                   96,

                                                   96,

                                                   PixelFormats.Pbgra32);

 

           DrawingVisual dv = new DrawingVisual();

        using (DrawingContext dc = dv.RenderOpen())

           {

               VisualBrush vb = new VisualBrush(element);

               dc.DrawRectangle(vb, null, new Rect(0, 0, width, height));

           }

           bmpCopied.Render(dv);

           return bmpCopied;

 }

 

Any ideas?