Hi,
I need to know how to extract a specific icon (32x32 for instance) from an
icon file that contains more than one icon size?
Any help would be highly appreciated,
Try this ;-)
Icon icon1 = IconFactory (@"C:\hoge.ico", 32, 32);
--
Hiroaki SHIBUKI [MVP]
--IconFactory.cs: BEGIN--
using System;
namespace hidori.Drawing
{
using System.Runtime.InteropServices;
using System.Drawing;
public class IconFactory
{
internal enum IMAGE_TYPE : uint
{
IMAGE_BITMAP = 0,
IMAGE_ICON = 1,
IMAGE_CURSOR = 2,
IMAGE_ENHMETAFILE = 3,
}
internal enum LR_FLAGS : uint
{
LR_DEFAULTCOLOR = 0x0000,
LR_MONOCHROME = 0x0001,
LR_COLOR = 0x0002,
LR_COPYRETURNORG = 0x0004,
LR_COPYDELETEORG = 0x0008,
LR_LOADFROMFILE = 0x0010,
LR_LOADTRANSPARENT = 0x0020,
LR_DEFAULTSIZE = 0x0040,
LR_VGACOLOR = 0x0080,
LR_LOADMAP3DCOLORS = 0x1000,
LR_CREATEDIBSECTION = 0x2000,
LR_COPYFROMRESOURCE = 0x4000,
LR_SHARED = 0x8000,
}
[DllImport("user32.dll")]
internal static extern System.IntPtr LoadImage
(
System.IntPtr hinst,
string lpszName,
IMAGE_TYPE uType,
int cxDesired,
int cyDesired,
LR_FLAGS fuLoad
);
public static Icon FromFile(string sFileName)
{
System.IntPtr hIcon = LoadImage (System.IntPtr.Zero, sFileName,
IMAGE_TYPE.IMAGE_ICON, 0, 0,
LR_FLAGS.LR_LOADFROMFILE|LR_FLAGS.LR_DEFAULTSIZE);
return Icon.FromHandle (hIcon);
}
public static Icon FromFile(string sFileName, int width, int height)
{
System.IntPtr hIcon = LoadImage (System.IntPtr.Zero, sFileName,
IMAGE_TYPE.IMAGE_ICON, width, height, LR_FLAGS.LR_LOADFROMFILE);
return Icon.FromHandle (hIcon);
}
public static Icon FromFile(string sFileName, Size size)
{
return FromFile (sFileName, size.Width, size.Height);
}
}
}
--IconFactory.cs: END--