locked
Using RenderTargetBitmap after an image has loaded

    Question

  • Hello,

    I'm developing an application that needs to render images in the background. 

    Actually I have a code that look like this

    <Grid x:Name="GridToRender">
     <ScrollViewer>
       <Image x:Name="ImageToLoad" Source={Binding ImageSource}"/>
       <Canvas>
        <!-- other content in usercontrol -->
       </Canvas>
     </ScrollViewer>
    </Grid>

    For my application, I change the binding value of the image to change the source, and render a bunch of images.

    My idea was every time the image and the content are loaded, I just have to call the function containing RenderTargetBitmap and render GridToRender.

    But, if I just catch the event Loaded on the image and the content, the view is not actually loaded. So I render an empty image. Moreover, if I change the source of the image through the binding, the Loaded event is never fired.

    Any suggestion?


    Wednesday, May 14, 2014 5:03 PM

Answers

All replies

  • Hi,

    Would you mind uploading a project to skyDrive and share a link in the forum or share a minimum project which can reproduce your problem. There is not enough information to test your problem.

    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Thursday, May 15, 2014 7:35 AM
  • Actually, simplifying my project to make a simple version will take me longer than just explain my problem. (and I suspect that this problem is a side effect of the rest of my project)

    So in a few words, I want to use RenderTargetBitmap to generate images. If I use this function with UIElement defined in xaml, it works perfectly.

    If I add element in the xaml code, and use RenderTargetBitmap to generate image, I need to wait until the UIElements are displayed on my screen. Otherwise, RenderTargetBitmap generates an empty image.

    To wait for my UIElement, I choose to use the event: Loaded. But, this event is call only once, after the page is loaded. So if I change the source of my image, it is never fired. 

    So, I try to use an other event: UpdateLayout. Unfortunately, I can't know why this event is fired. "LayoutUpdated is the last object lifetime event to occur in the sequence before a control is ready for interaction. However, LayoutUpdated can also occur at run time during the object lifetime, for a variety of reasons: a property change, a window resizing, or an explicit request."

    Do you have any idea of an event, or a function I can call to know when the UIElement is displayed on screen?

    Thursday, May 15, 2014 9:24 AM
  • Layout is different from rendering and isn't what you want. There isn't an event that a specific element has rendered. The BitmapImage's http://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.ui.xaml.media.imaging.bitmapimage.imageopened.aspx event will let you know when its imaged is loaded, which is probably the bottleneck

    • Marked as answer by BatRocchia Thursday, May 15, 2014 1:29 PM
    Thursday, May 15, 2014 12:43 PM
    Owner