locked
RenderTargetBitmap.Render() is not working well. RRS feed

  • Question

  • Hello guys,
    I am facing an Render(Visual) problem. I am using a simple Render(on MediaElement). It was working fine. However, if I add a border on it, or do HorizontalAlignment != Left, I got my video Render shifted and the rest will be black. For example, if my MediaElement is Aligned Vertical Center in a Grid, this means my MediaElement is shifted down. When I do render, it is render from the space before it is aligned to vertical center, so, I have some black on top and partial video render at bottom of my RenderTargetBitmap.

    I believe Render() method is targeting the Visual from the original spot. If my MediaElement is shifted by Alignment, the Render() method's target area didn't shift along with it.

    How do I resolve this? Thank you so much.


                        RenderTargetBitmap rtb = new RenderTargetBitmap(  
                            (int)this.x_Player.ActualWidth, (int)this.x_Player.ActualHeight,  
                            dpi.Width, dpi.Height, PixelFormats.Pbgra32);  
                        rtb.Render(this.x_Player); 

    Saturday, January 31, 2009 11:22 AM

Answers

  • LOL NVM,
    This is funny, I am being trying this for hours and now I just solved it in few minutes. So here is the trick I did. I just put my MediaElement in another container that will do Alignment LOL. Now my MediaElement doesn't move, thus, the Render() is good.

            <Grid Height="200" Width="200">  
                <Grid HorizontalAlignment="Center" VerticalAlignment="Center">  
                    <MediaElement Name="x_Player" IsHitTestVisible="False" 
                              Stretch="Uniform" ScrubbingEnabled="True" 
                              LoadedBehavior="Manual" UnloadedBehavior="Close" 
                              MediaEnded="Player_MediaEnded" /> 
                </Grid> 
            </Grid> 
     
    • Marked as answer by magicalclick Saturday, January 31, 2009 11:34 AM
    Saturday, January 31, 2009 11:33 AM

All replies

  • LOL NVM,
    This is funny, I am being trying this for hours and now I just solved it in few minutes. So here is the trick I did. I just put my MediaElement in another container that will do Alignment LOL. Now my MediaElement doesn't move, thus, the Render() is good.

            <Grid Height="200" Width="200">  
                <Grid HorizontalAlignment="Center" VerticalAlignment="Center">  
                    <MediaElement Name="x_Player" IsHitTestVisible="False" 
                              Stretch="Uniform" ScrubbingEnabled="True" 
                              LoadedBehavior="Manual" UnloadedBehavior="Close" 
                              MediaEnded="Player_MediaEnded" /> 
                </Grid> 
            </Grid> 
     
    • Marked as answer by magicalclick Saturday, January 31, 2009 11:34 AM
    Saturday, January 31, 2009 11:33 AM
  • Thank you so much!

    I am blocked by this problem just now, and I found here :)

    yeah, just do another nesting, it will be OK!
    Saturday, November 14, 2009 7:31 AM