protected override Icon Get(IntPtr nativeIcon, CacheIconCallback cacheIcon) { var icon = Icon.FromHandle(nativeIcon); cacheIcon(IconCache, icon.Width, icon); return(icon); }
public IconCacheTask(string path, FileAttributes attributes, CacheIconCallback callback) { Path = path; Attributes = attributes; Callback = callback; }
private IEnumerable <Image> GetImages(Stream stream, GetCacheIconCallback getCache, CacheIconCallback cacheIcon, out bool dispose) { Image source = Image.FromStream(stream); if (ImageFormat.Gif.Equals(source.RawFormat)) { // Gif cannot be cached/duplicated/or anything else, really. // underlying stream must not be closed (learned the hard way). dispose = false; cacheIcon(IconCache, source.Width, source); return(new[] { source }); } dispose = true; using (source) { if (ImageFormat.Icon.Equals(source.RawFormat)) { source.Dispose(); stream.Position = 0; var images = ReadIconStream(stream); foreach (var item in images) { cacheIcon(IconCache, item.Width, item); } return(images); } else if (ImageFormat.Tiff.Equals(source.RawFormat)) { List <Image> frames = new(); FrameDimension frameDimension = new(source.FrameDimensionsList[0]); var pageCount = source.GetFrameCount(FrameDimension.Page); for (int i = 0; i < pageCount; i++) { source.SelectActiveFrame(frameDimension, i); if (getCache(IconCache, source.Width)) { continue; } Bitmap copy = new(source); copy.SetResolution(96, 96); frames.Add(copy); cacheIcon(IconCache, copy.Width, copy); } return(frames); } else { Bitmap copy = new(source); copy.SetResolution(96, 96); cacheIcon(IconCache, copy.Width, copy); return(new[] { copy }); } } }