/// <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 = adaptor.GetUniqueIdentifier(key, 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();
            }
        }
Ejemplo n.º 2
0
 /// <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;
 }
Ejemplo n.º 3
0
        public TestForm()
        {
            InitializeComponent();

            Application.Idle += new EventHandler(Application_Idle);

            adaptor = new CustomAdaptor();
            uriAdaptor = new ImageListViewItemAdaptors.URIAdaptor();

            string picturePath = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
            files = Directory.GetFiles(picturePath, "*.jpg");

            imageListView.ThumbnailCaching += new Manina.Windows.Forms.ThumbnailCachingEventHandler(imageListView1_ThumbnailCaching);
            imageListView.ThumbnailCached += new Manina.Windows.Forms.ThumbnailCachedEventHandler(imageListView1_ThumbnailCached);
            imageListView.CacheError += new Manina.Windows.Forms.CacheErrorEventHandler(imageListView1_CacheError);
            imageListView.ItemCollectionChanged += new ItemCollectionChangedEventHandler(imageListView_ItemCollectionChanged);
            imageListView.KeyPress += new KeyPressEventHandler(imageListView_KeyPress);

            // Find and add built-in renderers
            Assembly assembly = Assembly.GetAssembly(typeof(ImageListView));
            foreach (Type type in assembly.GetTypes())
            {
                if (type.BaseType == typeof(ImageListView.ImageListViewRenderer))
                {
                    ToolStripMenuItem item = new ToolStripMenuItem(type.Name);
                    item.Click += SelectRenderer_Click;
                    SelectRenderer.DropDownItems.Add(item);
                }
            }
        }
 /// <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="requestType">Type of this request.</param>
 public CacheRequest(Guid guid, ImageListView.ImageListViewItemAdaptor adaptor, object key, Size size, UseEmbeddedThumbnails useEmbeddedThumbnails, bool autoRotate, RequestType requestType)
 {
     Guid                  = guid;
     VirtualItemKey        = key;
     Adaptor               = adaptor;
     Size                  = size;
     UseEmbeddedThumbnails = useEmbeddedThumbnails;
     AutoRotate            = autoRotate;
     RequestType           = requestType;
 }
        /// <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>
        /// Adds the virtual item image to the gallery cache queue.
        /// </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="useEmbeddedThumbnails">UseEmbeddedThumbnails property of the owner control.</param>
        /// <param name="autoRotate">AutoRotate property of the owner control.</param>
        public void AddToGalleryCache(Guid guid, ImageListView.ImageListViewItemAdaptor adaptor, object key, Size thumbSize, UseEmbeddedThumbnails useEmbeddedThumbnails, bool autoRotate)
        {
            // Already cached?
            if (galleryItem != null && galleryItem.Guid == guid && galleryItem.Image != null && galleryItem.Size == thumbSize && galleryItem.UseEmbeddedThumbnails == useEmbeddedThumbnails && galleryItem.AutoRotate == autoRotate)
            {
                return;
            }

            // Add to cache queue
            RunWorker(new CacheRequest(guid, adaptor, key, thumbSize, useEmbeddedThumbnails, autoRotate, RequestType.Gallery), 2);
        }
        /// <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>
        /// Gets the image from the thumbnail cache. If the image is not cached,
        /// null will be returned.
        /// </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>
        /// <param name="clone">true to return a clone of the cached image; otherwise false.</param>
        public Image GetImage(Guid guid, ImageListView.ImageListViewItemAdaptor adaptor, object key, Size thumbSize, UseEmbeddedThumbnails useEmbeddedThumbnails, bool autoRotate, bool useWIC, bool clone)
        {
            CacheItem item = null;

            if (thumbCache.TryGetValue(guid, out item) && item != null && item.Image != null && item.Size == thumbSize && item.UseEmbeddedThumbnails == useEmbeddedThumbnails && item.AutoRotate == autoRotate && item.UseWIC == useWIC)
            {
                return(clone ? (Image)item.Image.Clone() : item.Image);
            }
            else
            {
                string diskCacheKey = adaptor.GetUniqueIdentifier(key, thumbSize, useEmbeddedThumbnails, autoRotate, useWIC);

                // Check the disk cache
                using (Stream stream = diskCache.Read(diskCacheKey))
                {
                    if (stream.Length > 0)
                    {
                        return(new Bitmap(stream));
                    }
                }
                return(null);
            }
        }
Ejemplo n.º 9
0
        /// <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;
                }
            }

            // Add to cache
            thumbCache.Add(guid, new CacheItem(guid, thumbSize, ThumbnailExtractor.FromImage(thumb, thumbSize, useEmbeddedThumbnails, autoRotate, useWIC), CacheState.Cached, useEmbeddedThumbnails, autoRotate, useWIC));

            // Raise the cache events
            if (mImageListView != null)
            {
                mImageListView.OnThumbnailCachedInternal(guid, thumb, thumbSize, true);
                mImageListView.Refresh();
            }
        }
Ejemplo n.º 10
0
		internal ImageListViewFilter(ImageListView view, ImageListView.ImageListViewItemAdaptor adaptor)
		{
			mAdaptor = adaptor;
			mImageListView = view;
			mLastSearch = "";
		}
Ejemplo n.º 11
0
 /// <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));
 }
 /// <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>
 public CacheRequest(Guid guid, ImageListView.ImageListViewItemAdaptor adaptor, object virtualItemKey)
 {
     Guid           = guid;
     Adaptor        = adaptor;
     VirtualItemKey = virtualItemKey;
 }