Solved

Fill a listview with png file bitmap : too slow

Posted on 2006-11-07
2
933 Views
Last Modified: 2008-01-09
Hi Experts,

I populate my listview to get largeicons with filename and the picture of my png file like this (I use VirtualMode to speed up but it is very slow : near 900 pictures) :

private void PopulateListView()
        {
            items = new ListViewItem[DirInfo.GetFiles("*.png").Length];
            listView1.VirtualListSize = items.Length;
           
        }

        private void listView1_CacheVirtualItems(object sender, CacheVirtualItemsEventArgs e)
        {
            //// This code will loop through each item that is being invalidated and needs to be cache.
            //// It then adds each of those to the cache
            //for (int i = e.StartIndex; i < e.EndIndex; i++)
            //{
            //    //Save each item in the cache.
            //    items[i] = listView1.Items[i];
            //}
        }

        private void listView1_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e)
        {
            //This event is called when the ListView needs an item to display it.
            //This example will check if the item is already cached from a previous time
            //we displayed it. If it is not we will create the item and give it to the list view.
            //Note that we do not yet cache the item, the CacheVirtualItems method is called by the        
            //ListView when it is time to do that step

            ////check if we have cached it before
            //if (items[e.ItemIndex] == null)
            //{
                FileInfo file = files[e.ItemIndex];
                imageList1.Images.Add(e.ItemIndex.ToString(), ((Image)Bitmap.FromFile(file.FullName)).GetThumbnailImage(96,64,new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero));
                pictureBox1.PicBox.Image = imageList1.Images[e.ItemIndex.ToString()];
               
                ListViewItem item = new ListViewItem(file.Name,imageList1.Images.IndexOfKey(e.ItemIndex.ToString()));// e.ItemIndex.ToString());
               
                e.Item = item;
            //}
            //else
            //{
            //    //Cached. Return from cache
            //    e.Item = items[e.ItemIndex];
            //}
           
        }

        /// <summary>
        /// Required, but not used
        /// </summary>
        /// <returns>true</returns>
        public bool ThumbnailCallback()
        {
            return true;
        }

With Windows Explorer, the picture is displayed very quickly. Why not with my app ?

Thanks in advance for your help.
0
Comment
Question by:noulouk
2 Comments
 
LVL 4

Accepted Solution

by:
ostdp earned 500 total points
ID: 17893438
Windows explorer uses cacheing as well. If you turn off hide system files you will find a lot of "Thumbs.db" files in folders that you used to look at images. For rendering speed reasons you may want to use the BeginUpdate / EndUpdate methods on the listbox.
0
 
LVL 9

Author Comment

by:noulouk
ID: 17897820
The problem was the imagelist which didn't load quickly. I tweak it a little and that works better.
Thanks for your help.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now