IImage To Bitmap Source - CSharp System.Windows.Media.Imaging

CSharp examples for System.Windows.Media.Imaging:BitmapSource

Description

IImage To Bitmap Source

Demo Code


using System.Windows.Media.Imaging;
using System.Windows;
using System.Threading.Tasks;
using System.Text;
using System.Runtime.InteropServices;
using System.Linq;
using System.Collections.Generic;
using System;/* w  ww. j a  v a  2  s. co m*/
using Emgu.CV;

public class Main{
        public static BitmapSource ToBitmapSource(IImage image)
        {
            if (image == null) return null;
            using (System.Drawing.Bitmap source = image.Bitmap)
            {
                IntPtr ptr = source.GetHbitmap();

                BitmapSource bs = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
                    ptr,
                    IntPtr.Zero,
                    Int32Rect.Empty,
                    System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());

                DeleteObject(ptr);
                return bs;
            }
        }
}

Related Tutorials