Skip to content

Instantly share code, notes, and snippets.

@posaunehm
Created December 1, 2012 02:28
Show Gist options
  • Save posaunehm/4180255 to your computer and use it in GitHub Desktop.
Save posaunehm/4180255 to your computer and use it in GitHub Desktop.
extention method to create BitmapSource from hBitmap
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