Solved

Fill a listview with png file bitmap : too slow

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

773 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