Bookmark and Share Share...    Subscribe to this feed Feed   About me...


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);
    }
} 
 
 



 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!!!

Name
E-Mail (optional)
Comment
About Christian Moser