/// <summary> /// Adds a virtual item to the cache. /// </summary> /// <param name="guid">The guid representing this item.</param> /// <param name="adaptor">The adaptor for this item.</param> /// <param name="key">The key of this item.</param> /// <param name="thumbSize">Requested thumbnail size.</param> /// <param name="thumb">Thumbnail image to add to cache.</param> /// <param name="useEmbeddedThumbnails">UseEmbeddedThumbnails property of the owner control.</param> /// <param name="autoRotate">AutoRotate property of the owner control.</param> /// <param name="useWIC">Whether to use WIC.</param> public void Add(Guid guid, ImageListView.ImageListViewItemAdaptor adaptor, object key, Size thumbSize, Image thumb, UseEmbeddedThumbnails useEmbeddedThumbnails, bool autoRotate, bool useWIC) { // Already cached? CacheItem item = null; if (thumbCache.TryGetValue(guid, out item)) { if (item.Size == thumbSize && item.UseEmbeddedThumbnails == useEmbeddedThumbnails) { return; } } // Resize thumb = ThumbnailExtractor.FromImage(thumb, thumbSize, useEmbeddedThumbnails, autoRotate, useWIC); // Add to cache thumbCache.Add(guid, new CacheItem(guid, thumbSize, thumb, CacheState.Cached, useEmbeddedThumbnails, autoRotate, useWIC)); // Add to disk cache using (MemoryStream stream = new MemoryStream()) { string diskCacheKey = GetKey(guid, thumbSize, useEmbeddedThumbnails, autoRotate, useWIC); thumb.Save(stream, System.Drawing.Imaging.ImageFormat.Png); diskCache.Write(diskCacheKey, stream); } // Raise the cache events if (mImageListView != null) { mImageListView.OnThumbnailCachedInternal(guid, thumb, thumbSize, true); mImageListView.Refresh(); } }
/// <summary> /// Returns the thumbnail image for the given item. /// </summary> /// <param name="key">Item key.</param> /// <param name="size">Requested image size.</param> /// <param name="useEmbeddedThumbnails">Embedded thumbnail usage.</param> /// <param name="useExifOrientation">true to automatically rotate images based on Exif orientation; otherwise false.</param> /// <param name="useWIC">true to use Windows Imaging Component; otherwise false.</param> /// <returns>The thumbnail image from the given item or null if an error occurs.</returns> public override Image GetThumbnail(object key, Size size, UseEmbeddedThumbnails useEmbeddedThumbnails, bool useExifOrientation, bool useWIC) { if (disposed) { return(null); } string uri = (string)key; try { using (WebClient client = new WebClient()) { byte[] imageData = client.DownloadData(uri); using (MemoryStream stream = new MemoryStream(imageData)) { using (Image sourceImage = Image.FromStream(stream)) { return(ThumbnailExtractor.FromImage(sourceImage, size, useEmbeddedThumbnails, useExifOrientation, useWIC)); } } } } catch { return(null); } }
/// <summary> /// Returns the thumbnail image for the given item. /// </summary> /// <param name="key">Item key.</param> /// <param name="size">Requested image size.</param> /// <param name="useEmbeddedThumbnails">Embedded thumbnail usage.</param> /// <param name="useExifOrientation">true to automatically rotate images based on Exif orientation; otherwise false.</param> /// <param name="useWIC">true to use Windows Imaging Component; otherwise false.</param> /// <returns>The thumbnail image from the given item or null if an error occurs.</returns> public override Image GetThumbnail(object key, Size size, UseEmbeddedThumbnails useEmbeddedThumbnails, bool useExifOrientation, bool useWIC) { if (disposed) { return(null); } string filename = (string)key; if (File.Exists(filename)) { return(ThumbnailExtractor.FromFile(filename, size, useEmbeddedThumbnails, useExifOrientation, useWIC)); } else { return(null); } }
/// <summary> /// Returns the thumbnail image for the given item. /// </summary> /// <param name="key">Item key.</param> /// <param name="size">Requested image size.</param> /// <param name="useEmbeddedThumbnails">Embedded thumbnail usage.</param> /// <param name="useExifOrientation">true to automatically rotate images based on Exif orientation; otherwise false.</param> /// <param name="useWIC">true to use Windows Imaging Component; otherwise false.</param> /// <returns>The thumbnail image from the given item or null if an error occurs.</returns> public override Image GetThumbnail(object key, Size size, UseEmbeddedThumbnails useEmbeddedThumbnails, bool useExifOrientation, bool useWIC) { if (disposed) { return(null); } // [IG_CHANGE] // Issue #530: thumbnails not built if long file path string filename = Heart.Helpers.PrefixLongPath((string)key); if (File.Exists(filename)) { return(ThumbnailExtractor.FromFile(filename, size, useEmbeddedThumbnails, useExifOrientation, useWIC)); } else { return(null); } }