static Bitmap GetBitmap(Icon ic, CardWinExplorerDataSource.SizeIcon size, bool maybeMinIcon) { Bitmap src = ic.ToBitmap(); if (maybeMinIcon) { int sizeReal = CalcRealSize(src); if (sizeReal < 200) { src = src.Clone(new Rectangle(0, 0, (int)(sizeReal * dpiCoef2), (int)(sizeReal * dpiCoef2)), src.PixelFormat); switch (size) { case CardWinExplorerDataSource.SizeIcon.ExtraLarge: src = MakeBorder(new System.Drawing.Size((int)(256 * dpiCoef), (int)(256 * dpiCoef)), src, (int)(sizeReal * dpiCoef2)); break; case CardWinExplorerDataSource.SizeIcon.Large: src = MakeBorder(new System.Drawing.Size((int)(128 * dpiCoef), (int)(128 * dpiCoef)), src, (int)(sizeReal * dpiCoef2)); break; case CardWinExplorerDataSource.SizeIcon.Medium: src = MakeBorder(new System.Drawing.Size((int)(65 * dpiCoef), (int)(65 * dpiCoef)), src, (int)(sizeReal * dpiCoef2)); break; } } } return(src); }
static BitmapSource IconSource(Icon ic, CardWinExplorerDataSource.SizeIcon size, bool maybeMinIcon) { Bitmap src = GetBitmap(ic, size, maybeMinIcon); BitmapSource ic2 = Imaging.CreateBitmapSourceFromHBitmap(src.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); ic2.Freeze(); return(ic2); }
public static byte[] GetLargeIconByte(string fileName, bool maybeSmall, CardWinExplorerDataSource.SizeIcon sizeIcon = CardWinExplorerDataSource.SizeIcon.ExtraLarge) { IntPtr hIcon; Icon icon = GetFileIcon(fileName, out hIcon); byte[] byteIcon = IconByte(icon, sizeIcon, maybeSmall); icon.Dispose(); DestroyIcon(hIcon); return(byteIcon); }
public static BitmapSource GetLargeIcon(string fileName, bool maybeSmall, CardWinExplorerDataSource.SizeIcon sizeIcon = CardWinExplorerDataSource.SizeIcon.ExtraLarge) { IntPtr hIcon; Icon icon = GetFileIcon(fileName, out hIcon); BitmapSource bs = IconSource(icon, sizeIcon, maybeSmall); icon.Dispose(); DestroyIcon(hIcon); return(bs); }
void SetIcon(TypeElement type, string fullPath, CardWinExplorerDataSource.SizeIcon sizeType, int sizeInt) { Size = sizeInt; Size size = new Size(sizeInt, sizeInt); switch (type) { case TypeElement.Folder: FileName = Path.GetFileName(fullPath); if (folder == null) { folder = CardWinExplorerIconManager.GetLargeIconByte(fullPath, false); } Icon = folder; break; case TypeElement.File: FileName = Path.GetFileName(fullPath); string ext = System.IO.Path.GetExtension(fullPath); if (ext == ".exe" || ext == ".lnk") { Icon = CardWinExplorerIconManager.GetLargeIconByte(fullPath, true, sizeType); } else if (!cache.ContainsKey(ext)) { byte[] bi = CardWinExplorerIconManager.GetLargeIconByte(fullPath, true, sizeType); cache.Add(ext, bi); Icon = bi; } else { Icon = cache[ext]; } break; case TypeElement.Drive: FileName = fullPath; Icon = CardWinExplorerIconManager.GetLargeIconByte(fullPath, false); break; default: break; } }
static byte[] IconByte(Icon ic, CardWinExplorerDataSource.SizeIcon size, bool maybeMinIcon) { ImageConverter converter = new ImageConverter(); return((byte[])converter.ConvertTo(GetBitmap(ic, size, maybeMinIcon), typeof(byte[]))); }
public void Resize(CardWinExplorerDataSource.SizeIcon sizeType, int sizeInt) { SetIcon(Type, FullPath, sizeType, sizeInt); }
public CardWinExplorerFileSource(string fullPath, TypeElement type, CardWinExplorerDataSource.SizeIcon sizeType, int size) { Type = type; FullPath = fullPath; SetIcon(type, fullPath, sizeType, size); }