Пример #1
0
        /// <summary>
        /// Gets the icon or thumbnail for a file or directory
        /// </summary>
        /// <param name="path">The path of the file or directory to get the icon or thumbnail for</param>
        /// <param name="shellThumbnailSize">The size of the icon or thumbnail</param>
        /// <param name="getIcon">True if the icon should be returned or false if the thumbnail should be returned</param>
        /// <returns>The icon or thumbnail</returns>
        public static Bitmap GetIconOrThumbnail(string path, ShellThumbnailSize shellThumbnailSize, bool getIcon = true)
        {
            using var shellObject = ShellObject.FromParsingName(path);

            var thumb = shellObject.Thumbnail;

            thumb.FormatOption = getIcon ? ShellThumbnailFormatOption.IconOnly : ShellThumbnailFormatOption.ThumbnailOnly;
            return(thumb.GetTransparentBitmap(shellThumbnailSize));
        }
Пример #2
0
 public static Bitmap GetTransparentBitmap(this ShellThumbnail shellThumbnail, ShellThumbnailSize shellThumbnailSize = ShellThumbnailSize.Default)
 {
     return(shellThumbnailSize switch
     {
         ShellThumbnailSize.Default => CreateAlphaBitmap(shellThumbnail.Bitmap, PixelFormat.Format32bppArgb),
         ShellThumbnailSize.Small => CreateAlphaBitmap(shellThumbnail.SmallBitmap, PixelFormat.Format32bppArgb),
         ShellThumbnailSize.Medium => CreateAlphaBitmap(shellThumbnail.MediumBitmap, PixelFormat.Format32bppArgb),
         ShellThumbnailSize.Large => CreateAlphaBitmap(shellThumbnail.LargeBitmap, PixelFormat.Format32bppArgb),
         ShellThumbnailSize.ExtraLarge => CreateAlphaBitmap(shellThumbnail.ExtraLargeBitmap, PixelFormat.Format32bppArgb),
         _ => CreateAlphaBitmap(shellThumbnail.Bitmap, PixelFormat.Format32bppArgb)
     });
Пример #3
0
        /// <summary>
        /// Gets a transparent bitmap icon or thumbnail from a <see cref="ShellThumbnail"/> based on size
        /// </summary>
        /// <param name="shellThumbnail">The shell thumbnail to get the bitmap from</param>
        /// <param name="shellThumbnailSize">The size of the thumbnail or icon to retrieve</param>
        /// <returns>The thumbnail or icon</returns>
        public static Bitmap GetTransparentBitmap(this ShellThumbnail shellThumbnail, ShellThumbnailSize shellThumbnailSize = ShellThumbnailSize.Default)
        {
            switch (shellThumbnailSize)
            {
            default:
            case ShellThumbnailSize.Default:
                return(CreateAlphaBitmap(shellThumbnail.Bitmap, PixelFormat.Format32bppArgb));

            case ShellThumbnailSize.Small:
                return(CreateAlphaBitmap(shellThumbnail.SmallBitmap, PixelFormat.Format32bppArgb));

            case ShellThumbnailSize.Medium:
                return(CreateAlphaBitmap(shellThumbnail.MediumBitmap, PixelFormat.Format32bppArgb));

            case ShellThumbnailSize.Large:
                return(CreateAlphaBitmap(shellThumbnail.LargeBitmap, PixelFormat.Format32bppArgb));

            case ShellThumbnailSize.ExtraLarge:
                return(CreateAlphaBitmap(shellThumbnail.ExtraLargeBitmap, PixelFormat.Format32bppArgb));
            }