locked
How to get image from label control RRS feed

  • Question

  • I found some artcile of how to get image from control.

    http://wpftutorial.net/BitmapFromVisual.html

    http://www.dreamincode.net/code/snippet4326.htm

    I want to create label programatically and create image from it. But it doesn't work.

    I try something like this

    var label = new Label();            
    label.Content = "Hello";
    label.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
    label.VerticalAlignment = System.Windows.VerticalAlignment.Top;
    label.Margin = new Thickness(0,0,0,0);
    
    RenderTargetBitmap bitmap = new RenderTargetBitmap(width, height, 96, 96,
                                                     PixelFormats.Pbgra32);
    bitmap.Render(label);
    
    
    And it doesn't work ((


    Video Frame Explorer allows you to make thumbnails (caps, previews) of video files

    My .NET Extras. Coming soon : MVVM Dialog Service, EmptyIfNull ( LINQ ), CombineAsPath, Easy File Size Info

    Tuesday, July 17, 2012 6:47 AM

Answers

  • Try this code, there are other ways, but this code looked good to me.

    JP Cowboy Coders Unite!

    • Proposed as answer by Michael Stacie Tuesday, July 17, 2012 4:25 PM
    • Marked as answer by SmartWhy Friday, July 20, 2012 8:08 AM
    Tuesday, July 17, 2012 12:31 PM

All replies

  • Try this code, there are other ways, but this code looked good to me.

    JP Cowboy Coders Unite!

    • Proposed as answer by Michael Stacie Tuesday, July 17, 2012 4:25 PM
    • Marked as answer by SmartWhy Friday, July 20, 2012 8:08 AM
    Tuesday, July 17, 2012 12:31 PM
  • Yes the above post is correct.  That is how it is done.  You have to render the visual before you can take an image of it.

    Michael Stacie

    Tuesday, July 17, 2012 4:25 PM