Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Fill a listview with png file bitmap : too slow

Posted on 2006-11-07
2
Medium Priority
?
943 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 2000 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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

604 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