AGS.Editor.Utilities.ImageToIcon C# (CSharp) Метод

ImageToIcon() публичный статический Метод

Converts an image to icon. Code taken from comments section in: http://ryanfarley.com/blog/archive/2004/04/06/507.aspx
public static ImageToIcon ( Image image ) : Icon
image Image The image
Результат System.Drawing.Icon
        public static Icon ImageToIcon(Image image)
        {
            Icon icon = null;

            Bitmap bitmap = new Bitmap(image);
            IntPtr UnmanagedIconHandle = bitmap.GetHicon();

            // Clone FromHandle result so we can destroy the unmanaged handle version of the icon before the converted object is passed out.
            icon = Icon.FromHandle(UnmanagedIconHandle).Clone() as Icon;

            //Unfortunately, GetHicon creates an unmanaged handle which must be manually destroyed otherwise a generic error will occur in GDI+.
            DestroyIcon(UnmanagedIconHandle);

            return icon;
        }

Usage Example

Пример #1
0
 private void SetIcon(ContentDocument pane)
 {
     if (string.IsNullOrEmpty(pane.IconKey))
     {
         pane.Control.DockingContainer.Icon = Factory.GUIController.MainIcon;
     }
     else
     {
         Image iconImage =
             Factory.GUIController.ImageList.Images[pane.IconKey];
         pane.Control.DockingContainer.Icon = Utilities.ImageToIcon(iconImage);
     }
 }