Converts a Bitmap to an Icon - CSharp System.Drawing

CSharp examples for System.Drawing:Image Convert

Description

Converts a Bitmap to an Icon

Demo Code


using System.IO;//w  w  w . jav a2  s  .c  o m
using System.Drawing;

public class Main{
        /// <summary>
        /// Converts a <see cref="Bitmap"/> to a <see cref="Icon"/>
        /// </summary>
        public static Icon ToIcon(this Bitmap bitmap)
        {
            try
            {
                if (bitmap != null)
                {
                    return Icon.FromHandle(bitmap.GetHicon());
                }
            }
            catch
            {
                return null;
            }

            return null;
        }
}

Related Tutorials