Ejemplo n.º 1
0
 public static Bitmap ExtractHighResIconImage(string path, int? size = null)
 {
     var mi = new MultiIcon();
     mi.Load(path);
     var si = mi.FirstOrDefault();
     if (si != null)
     {
         IconImage icon;
         if (size != null)
         {
             if (size.Value <= 32)
             {
                 try
                 {
                     return Icon.ExtractAssociatedIcon(path).ToBitmap();
                 }
                 catch
                 {
                 }
             }
             icon = si.Where(x => x.Size.Height >= size.Value).OrderBy(x => x.Size.Height).FirstOrDefault();
             if (icon != null)
                 return icon.Icon.ToBitmap();
         }
         var max = si.Max(_i => _i.Size.Height);
         icon = si.FirstOrDefault(i => i.Size.Height == max);
         if(icon != null)
             return icon.Transparent;
     }
     return null;
 }
        public static Bitmap ExtractHighResIconImage(string path, int?size = null)
        {
            var mi = new MultiIcon();

            mi.Load(path);
            var si = mi.FirstOrDefault();

            if (si != null)
            {
                IconImage icon;
                if (size != null)
                {
                    if (size.Value <= 32)
                    {
                        try
                        {
                            return(Icon.ExtractAssociatedIcon(path).ToBitmap());
                        }
                        catch
                        {
                        }
                    }
                    icon = si.Where(x => x.Size.Height >= size.Value).OrderBy(x => x.Size.Height).FirstOrDefault();
                    if (icon != null)
                    {
                        return(icon.Icon.ToBitmap());
                    }
                }
                var max = si.Max(_i => _i.Size.Height);
                icon = si.FirstOrDefault(i => i.Size.Height == max);
                if (icon != null)
                {
                    return(icon.Transparent);
                }
            }
            return(null);
        }
Ejemplo n.º 3
0
        public static Bitmap ExtractHighResIconImage(string path, int?size = null)
        {
            MultiIcon source1  = new MultiIcon();
            string    fileName = path;

            source1.Load(fileName);
            SingleIcon source2 = source1.FirstOrDefault <SingleIcon>();

            if (source2 != null)
            {
                if (size.HasValue)
                {
                    if (size.Value <= 32)
                    {
                        try
                        {
                            return(Icon.ExtractAssociatedIcon(path).ToBitmap());
                        }
                        catch
                        {
                        }
                    }
                    IconImage iconImage = source2.Where <IconImage>((Func <IconImage, bool>)(x => x.Size.Height >= size.Value)).OrderBy <IconImage, int>((Func <IconImage, int>)(x => x.Size.Height)).FirstOrDefault <IconImage>();
                    if (iconImage != null)
                    {
                        return(iconImage.Icon.ToBitmap());
                    }
                }
                int       max        = source2.Max <IconImage>((Func <IconImage, int>)(_i => _i.Size.Height));
                IconImage iconImage1 = source2.FirstOrDefault <IconImage>((Func <IconImage, bool>)(i => i.Size.Height == max));
                if (iconImage1 != null)
                {
                    return(iconImage1.Transparent);
                }
            }
            return((Bitmap)null);
        }