Bookmark and Share Share...    Subscribe to this feed Feed   About Christian Moser  


How to get a Bitmap from a Visual

 
public void SaveImage(Visual visual, int width, int height, string filePath)
{
    RenderTargetBitmap bitmap = new RenderTargetBitmap(width, height, 96, 96,
                                                 PixelFormats.Pbgra32);
    bitmap.Render(visual);
 
    PngBitmapEncoder image = new PngBitmapEncoder();
    image.Frames.Add(BitmapFrame.Create(bitmap));
    using (Stream fs = File.Create(filePath))
    {
        image.Save(fs);
    }
} 
 
 




Last modified: 2009-07-13 11:28:57
Copyright (c) by Christian Moser, 2011.

 Comments on this article

Show all comments
Sachin
Commented on 24.November 2009
Awesome post!! thats what I was looking for.
Thanks.
Rahul Mehta
Commented on 6.August 2010
Nice One!!!
Kc
Commented on 3.May 2011
Thanks a lot !!!!

Name
E-Mail (optional)
Comment