/// <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> /// Initializes a new instance of the <see cref="CacheRequest"/> class. /// </summary> /// <param name="guid">The guid of the item.</param> /// <param name="adaptor">The adaptor of this item.</param> /// <param name="virtualItemKey">The virtual item key of this item.</param> /// <param name="useWIC">Whether to use the Windows Imaging Component.</param> public CacheRequest(Guid guid, ImageListView.ImageListViewItemAdaptor adaptor, object virtualItemKey, bool useWIC) { Guid = guid; Adaptor = adaptor; VirtualItemKey = virtualItemKey; UseWIC = useWIC; }
/// <summary> /// Adds the virtual item image to the renderer cache queue. /// </summary> /// <param name="guid">The guid representing this item.</param> /// <param name="adaptor">The adaptor of this item.</param> /// <param name="key">The key of this item.</param> /// <param name="thumbSize">Requested thumbnail size.</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 AddToRendererCache(Guid guid, ImageListView.ImageListViewItemAdaptor adaptor, object key, Size thumbSize, UseEmbeddedThumbnails useEmbeddedThumbnails, bool autoRotate, bool useWIC) { // Already cached? if (rendererItem != null && rendererItem.Guid == guid && rendererItem.Image != null && rendererItem.Size == thumbSize && rendererItem.UseEmbeddedThumbnails == useEmbeddedThumbnails && rendererItem.AutoRotate == autoRotate && rendererItem.UseWIC == useWIC) { return; } // Add to cache queue RunWorker(new CacheRequest(guid, adaptor, key, thumbSize, useEmbeddedThumbnails, autoRotate, useWIC, RequestType.Renderer), 1); }
/// <summary> /// Initializes a new instance of the <see cref="CacheRequest"/> class /// for use with a virtual item. /// </summary> /// <param name="guid">The guid of the ImageListViewItem.</param> /// <param name="adaptor">The adaptor of this item.</param> /// <param name="key">The public key for the virtual item.</param> /// <param name="size">The size of the requested thumbnail.</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> /// <param name="requestType">Type of this request.</param> public CacheRequest(Guid guid, ImageListView.ImageListViewItemAdaptor adaptor, object key, Size size, UseEmbeddedThumbnails useEmbeddedThumbnails, bool autoRotate, bool useWIC, RequestType requestType) { Guid = guid; VirtualItemKey = key; Adaptor = adaptor; Size = size; UseEmbeddedThumbnails = useEmbeddedThumbnails; AutoRotate = autoRotate; UseWIC = useWIC; RequestType = requestType; }
/// <summary> /// Adds a virtual item to the cache queue. /// </summary> /// <param name="guid">The guid representing this item.</param> /// <param name="adaptor">he adaptor for this item.</param> /// <param name="key">The key of this item.</param> /// <param name="thumbSize">Requested thumbnail size.</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, 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; } } // Add to cache queue RunWorker(new CacheRequest(guid, adaptor, key, thumbSize, useEmbeddedThumbnails, autoRotate, useWIC, RequestType.Thumbnail)); }
/// <summary> /// Adds the item to the cache queue. /// </summary> /// <param name="guid">Item guid.</param> /// <param name="adaptor">The adaptor for this item.</param> /// <param name="virtualItemKey">The virtual item key.</param> /// <param name="useWIC">Whether to use the Windows Imaging Component.</param> public void Add(Guid guid, ImageListView.ImageListViewItemAdaptor adaptor, object virtualItemKey, bool useWIC) { // Add to cache queue RunWorker(new CacheRequest(guid, adaptor, virtualItemKey, useWIC)); }