Mercurial > silverbladetech
comparison Chronosv2/source/Extensions/Windows/BitmapSourceExtensions.cs @ 10:443821e55f06
Initial cleaned up add from Codeplex files
author | stevenh7776 stevenhollidge@hotmail.com |
---|---|
date | Tue, 21 Feb 2012 17:25:44 +0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
9:904a9faadf8b | 10:443821e55f06 |
---|---|
1 using System; | |
2 using System.Drawing; | |
3 using System.IO; | |
4 using System.Windows.Media.Imaging; | |
5 | |
6 namespace Chronos.Extensions.Windows | |
7 { | |
8 /// <summary> | |
9 /// Extension methods for the System.Windows.Media.Imaging.BitmapSource class | |
10 /// </summary> | |
11 public static class BitmapSourceExtensions | |
12 { | |
13 #region · Extensions · | |
14 | |
15 /// <summary> | |
16 /// Create a System.Drawing.Bitmap from the passed WPF BitmapSource instance | |
17 /// </summary> | |
18 /// <param name="bitmapSource">The bitmap source.</param> | |
19 /// <returns>The generated bitmap</returns> | |
20 public static Bitmap ToBitmap(this BitmapSource bitmapSource) | |
21 { | |
22 var encoder = new BmpBitmapEncoder(); | |
23 encoder.Frames.Add(BitmapFrame.Create(bitmapSource)); | |
24 | |
25 using (var stream = new MemoryStream()) | |
26 { | |
27 encoder.Save(stream); | |
28 | |
29 // Nested construction required to prevent issues from closing the underlying stream | |
30 return new Bitmap(new Bitmap(stream)); | |
31 } | |
32 } | |
33 | |
34 #endregion | |
35 } | |
36 } |