示例#1
0
        public static Icon[] FromFile(string fileName)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException(nameof(fileName), PublicResources.ArgumentNull);
            }
            if (!OSUtils.IsWindows)
            {
                Reflector.EmptyArray <Icon>();
            }

            IntPtr[][] handles = Shell32.ExtractIconHandles(fileName, null);
            Icon[]     result  = new Icon[handles.Length];

            for (int i = 0; i < handles.Length; i++)
            {
                result[i] = Combine(handles[i].Select(Icon.FromHandle).ToArray());
                foreach (IntPtr handle in handles[i])
                {
                    User32.DestroyIcon(handle);
                }
            }

            return(result);
        }
示例#2
0
        public static Icon[] FromFile(string fileName, SystemIconSize size)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException(nameof(fileName), PublicResources.ArgumentNull);
            }
            if (!Enum <SystemIconSize> .IsDefined(size))
            {
                throw new ArgumentOutOfRangeException(nameof(size), PublicResources.EnumOutOfRangeWithValues(size));
            }
            if (!OSUtils.IsWindows)
            {
                Reflector.EmptyArray <Icon>();
            }

            IntPtr[][] handles = Shell32.ExtractIconHandles(fileName, size);
            Icon[]     result  = new Icon[handles.Length];

            for (int i = 0; i < handles.Length; i++)
            {
                result[i] = Icon.FromHandle(handles[i][0]).ToManagedIcon();
            }

            return(result);
        }