Created
December 1, 2012 02:28
-
-
Save posaunehm/4180255 to your computer and use it in GitHub Desktop.
extention method to create BitmapSource from hBitmap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class HBitmapExtention | |
{ | |
/// <summary> | |
/// ref: http://nine-works.blog.ocn.ne.jp/blog/2011/12/post_b0e8.html | |
/// </summary> | |
/// <param name="hBitmapSource">hBitmap</param> | |
/// <returns>BitmapSource</returns> | |
public static BitmapSource ToBitmapSource(this IntPtr hBitmapSource) | |
{ | |
return Imaging.CreateBitmapSourceFromHBitmap( | |
hBitmapSource, | |
IntPtr.Zero, | |
Int32Rect.Empty, | |
BitmapSizeOptions.FromEmptyOptions() | |
); | |
} | |
} | |
public class User | |
{ | |
public void Use() | |
{ | |
SomeImage.Source = Properties.Resources.Pict.ToToBitmapSource(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment