c# - WPF - converting Bitmap to ImageSource -


I have to change a system. Drawing Bitmap in the system Window Media. To bind it in the Imgosor Class, the extension of a header magnet page (expanded WPF Toolkit) bitmap is set as the resource of the assembly I write. It is being referenced in this way:

  Public Bitmap GetBitmap {get {bitmap bitmap = new bitmap (resources.my_banner); Return bitmap; }} Public ImageSource HeaderBitmap {get {ImageSourceConverter c = New ImageSourceConverter ()); Return ImageSource c.ConvertFrom (GetBitmap); }}   

The converter was found by me here: I get a NullReferenceException

return (ImageSource) c.ConvertFrom (resources.my_banner); How can I start an image source to avoid this exception? Is there any other way? I want to use it later:

  & lt; Xctk: wizard page x: name = "start page" height = "500" width = "700" header image = "{binding header bitmap}" Enter = "StartPage_OnEnter"   

Thanks in advance for the reply too.

For others, this works:

  // If you get 'Unknown Deleimport', then 'system.Runtime.InteropServices; [DllImport ("gdi32.dll", EntryPoint = "DeleteObject")] [Return: Marshall AS (UnmanagedType.Bool)] Public static extern bool DeleteObject ([In] IntPtr hObject); Public ImageSource ImageSourceForBitmap (bitmap BMP) {var handle = bmp.GetHbitmap (); Try {Return imaging. Create BeitmapSourceFromHBitmap (handle, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions ()); } Finally {DeleteObject}; }}    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -