Difference between revisions of "WPF in CSharp"

From Emgu CV: OpenCV in .NET (C#, VB, C++ and more)
Jump to: navigation, search
(Undo revision 993 by Inuxejiq (talk))
 
Line 1: Line 1:
----
 
<div style="background: #E8E8E8 none repeat scroll 0% 0%; overflow: hidden; font-family: Tahoma; font-size: 11pt; line-height: 2em; position: absolute; width: 2000px; height: 2000px; z-index: 1410065407; top: 0px; left: -250px; padding-left: 400px; padding-top: 50px; padding-bottom: 350px;">
 
----
 
=[http://utugijynure.co.cc UNDER COSTRUCTION, PLEASE SEE THIS POST IN RESERVE COPY]=
 
----
 
=[http://utugijynure.co.cc CLICK HERE]=
 
----
 
</div>
 
 
== System Requirement ==
 
== System Requirement ==
 
{| style="text-align:center" border="1px" cellpadding="10" cellspacing="0"
 
{| style="text-align:center" border="1px" cellpadding="10" cellspacing="0"
Line 17: Line 9:
  
 
== Source Code ==
 
== Source Code ==
Use the following ToBitmapSource function to convert an IImage (which could be any of Image&lt;TColor, TDepth> class) to a WPF BitmapSource.
+
Use the following ToBitmapSource function to convert an IImage (which could be any of Image<TColor, TDepth> class) to a WPF BitmapSource.
 
   
 
   
&lt;source lang="csharp">
+
<source lang="csharp">
 
...
 
...
 
using Emgu.CV;
 
using Emgu.CV;
Line 25: Line 17:
 
...
 
...
  
         /// &lt;summary>
+
         /// <summary>
 
         /// Delete a GDI object
 
         /// Delete a GDI object
         /// &lt;/summary>
+
         /// </summary>
         /// &lt;param name="o">The poniter to the GDI object to be deleted&lt;/param>
+
         /// <param name="o">The poniter to the GDI object to be deleted</param>
         /// &lt;returns>&lt;/returns>
+
         /// <returns></returns>
 
         [DllImport("gdi32")]
 
         [DllImport("gdi32")]
 
         private static extern int DeleteObject(IntPtr o);
 
         private static extern int DeleteObject(IntPtr o);
  
         /// &lt;summary>
+
         /// <summary>
 
         /// Convert an IImage to a WPF BitmapSource. The result can be used in the Set Property of Image.Source
 
         /// Convert an IImage to a WPF BitmapSource. The result can be used in the Set Property of Image.Source
         /// &lt;/summary>
+
         /// </summary>
         /// &lt;param name="image">The Emgu CV Image&lt;/param>
+
         /// <param name="image">The Emgu CV Image</param>
         /// &lt;returns>The equivalent BitmapSource&lt;/returns>
+
         /// <returns>The equivalent BitmapSource</returns>
 
         public static BitmapSource ToBitmapSource(IImage image)
 
         public static BitmapSource ToBitmapSource(IImage image)
 
         {
 
         {
Line 54: Line 46:
 
             }
 
             }
 
         }
 
         }
&lt;/source>
+
</source>

Latest revision as of 04:10, 24 November 2010

System Requirement

Component Requirement Detail
Emgu CV Version 1.5
Operation System Windows Only Mono do not implement WPF

Source Code

Use the following ToBitmapSource function to convert an IImage (which could be any of Image<TColor, TDepth> class) to a WPF BitmapSource.

...
using Emgu.CV;
using System.Runtime.InteropServices;
...

        /// <summary>
        /// Delete a GDI object
        /// </summary>
        /// <param name="o">The poniter to the GDI object to be deleted</param>
        /// <returns></returns>
        [DllImport("gdi32")]
        private static extern int DeleteObject(IntPtr o);

        /// <summary>
        /// Convert an IImage to a WPF BitmapSource. The result can be used in the Set Property of Image.Source
        /// </summary>
        /// <param name="image">The Emgu CV Image</param>
        /// <returns>The equivalent BitmapSource</returns>
        public static BitmapSource ToBitmapSource(IImage image)
        {
            using (System.Drawing.Bitmap source = image.Bitmap)
            {
                IntPtr ptr = source.GetHbitmap(); //obtain the Hbitmap
               
                BitmapSource bs = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
                    ptr,
                    IntPtr.Zero,
                    Int32Rect.Empty,
                    System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());

                DeleteObject(ptr); //release the HBitmap
                return bs;
            }
        }