Solved

Fill a listview with png file bitmap : too slow

Posted on 2006-11-07
2
940 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

688 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