110,534
社区成员
发帖
与我相关
我的任务
分享
private void SaveIcon(Icon icon)
{
FileStream fs = new FileStream("E:\\save.ico", FileMode.Create, FileAccess.Write);
//通过文件流保存
icon.Save(fs);
fs.Flush();
fs.Close();
fs.Dispose();
}
[DllImport("shell32.dll", CharSet = CharSet.Auto)]
private static extern int ExtractIconEx(string path, int i, IntPtr[] big, IntPtr[] small, uint op);
private void GetIcons(string FilePath, ref List LargeIconList, ref List SmallIconList)
{
//判断并实例化图标列表
if (LargeIconList == null) LargeIconList = new List();
if (SmallIconList == null) SmallIconList = new List();
//清空列表
LargeIconList.Clear();
SmallIconList.Clear();
//获得图标总数
int IconsNum = ExtractIconEx(FilePath, -1, null, null, 0);
//大图标和小图标的"句柄"(指针)数组
IntPtr[] LargeIcons = new IntPtr[IconsNum];
IntPtr[] SmallIcons = new IntPtr[IconsNum];
//读取全部图标,并保存在句柄数组中
ExtractIconEx(FilePath, 0, LargeIcons, SmallIcons, (uint)IconsNum);
//转换成对应的图标数组
for (int i = 0; i < IconsNum; i++)
{
//大图标
LargeIconList.Add(Icon.FromHandle(LargeIcons[i]));
//小图标
SmallIconList.Add(Icon.FromHandle(SmallIcons[i]));
}
}