Solved

Fill a listview with png file bitmap : too slow

Posted on 2006-11-07
2
936 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

863 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

23 Experts available now in Live!

Get 1:1 Help Now