BitmapSource Converted From Bitmap Image - CSharp System.Windows.Media.Imaging

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

Description

BitmapSource Converted From Bitmap Image

Demo Code


using System.Windows.Media.Imaging;
using System.Windows.Interop;
using System.Windows;
using System.Drawing;
using System;// ww w  . j a  v a 2s.  c  o  m

public class Main{
        public static BitmapSource ConvertFromImage(Bitmap image)
        {
            IntPtr hBitmap = image.GetHbitmap();

            try
            {
                var bs = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
                    hBitmap,
                    //Properties.Resources.logoITC_Revit.GetHbitmap(),
                    IntPtr.Zero,
                    System.Windows.Int32Rect.Empty,
                    BitmapSizeOptions.FromEmptyOptions());

                return bs;

            }
            finally
            {
                DeleteObject(hBitmap);
            }

        }
}

Related Tutorials