protected virtual BitmapSource GetShellBitmap() { Win32Shell.SHFILEINFO shInfo = new Win32Shell.SHFILEINFO(); Win32Shell.SHGetFileInfo(FullPath, 0, ref shInfo, (uint)Marshal.SizeOf(shInfo), Win32Shell.SHGFI_ICON | Win32Shell.SHGFI_SMALLICON | Win32Shell.SHGFI_SYSICONINDEX); return(Imaging.CreateBitmapSourceFromHIcon(shInfo.hIcon, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions())); }
protected override BitmapSource GetShellBitmap() { IntPtr pidRoot = IntPtr.Zero; Win32Shell.SHFILEINFO shInfo = new Win32Shell.SHFILEINFO(); BitmapSource bmp; Win32Shell.SHGetKnownFolderIDList(NodeGuid, 0, IntPtr.Zero, out pidRoot); Win32Shell.SHGetFileInfo(pidRoot, 0, ref shInfo, (uint)Marshal.SizeOf(shInfo), Win32Shell.SHGFI_ICON | Win32Shell.SHGFI_SMALLICON | Win32Shell.SHGFI_PIDL); bmp = Imaging.CreateBitmapSourceFromHIcon(shInfo.hIcon, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); // bmp.Save(@"c:\temp\pc.png"); if (pidRoot != IntPtr.Zero) { Win32Shell.IMalloc malloc; Win32Shell.SHGetMalloc(out malloc); malloc.Free(pidRoot); } return(bmp); }
/// <summary> /// /// </summary> /// <param name="fileName"></param> /// <returns></returns> public ImageSource GetImageFromExt(string fileName) { string ext; if (string.IsNullOrEmpty(fileName)) { return(null); } ext = Path.GetExtension(fileName); if (string.IsNullOrEmpty(ext)) { return(null); } if (!FileImage.ContainsKey(ext)) { Win32Shell.SHFILEINFO shInfo = new Win32Shell.SHFILEINFO(); Win32Shell.SHGetFileInfo(fileName, 0, ref shInfo, (uint)Marshal.SizeOf(shInfo), Win32Shell.SHGFI_ICON | Win32Shell.SHGFI_SMALLICON | Win32Shell.SHGFI_SYSICONINDEX); FileImage[ext] = Imaging.CreateBitmapSourceFromHIcon(shInfo.hIcon, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); } return(FileImage[ext]); }