I have been trying to solve this problem without any luck. Can someone please have a look at this code as it doesn't work

Thank you

After clicking a button I refresh the picture box the
code below is in the picbox.Paint event. Basically what I am trying to do is to write a series of thumbnails to a buffer, then show the screen with all the thumbnails in place,
I can do it without buffering but it is very slow.

Any help welcome

_Buffer= new Bitmap(363,420);
            Graphics g = e.Graphics;    
            for (int y1 = 0; y1 < 12; y1++)
                    Point P1 = pp.Get_ThumbNail_Point_Pos(y1);
                    theImage = new Bitmap(pp.pics[y1]);
                    imgThumb =    theImage.GetThumbnailImage(98, 98, null, new IntPtr());
                    g.DrawImage(_Buffer, P1);
              e.Graphics.DrawImageUnscaled(_Buffer, 0, 0);

Edited by __avd: code tags corrected.

8 Years
Discussion Span
Last Post by valter

The way you are doing it isn't bad, you just aren't using the buffer idea correctly, the paint event should just draw the buffer image, nothing else. all the other stuff including the loop should be done in a loadthumbs method, what you have accomplished is to reload the images and draw them to disk EVERY time the picbox invalidates.

but a better way to do it would be to use multiple picture boxes on a user control, the picturebox has a Asynchronous image loading method build into it. So it would be very simple!

create a usercontrol that has a collection of image locations as a property, when the property is changed, have the usercontrol loop through and create a picturebox for each element in the collection and load the images using the Asynchronous load method of the picturebox. And presto, easy, fast, effective, and elegant control, that is reusable, and fits your needs.


Thanks D.

I had a look at the links, but don't understand, I will do more research on the thread idea.


Thanks for your comments. I did recognize picbox would paint every time but I have an if that tests whether it should.
I am intrigued by your idea of a usercontrol, haven't used image list. When you say create a new picbox for each thumb, I thought I would be faster to put each image in same picbox in memory then show it. Am I understanding you when you say use a separate box for each image?


a separate picture box for each image yes, your bottleneck in performance will be loading the images from disk, Creating a new image using the images is just an extra step that is even slower, a few picturebox controls won't suffer you any performance. Its the images that they hold in memory that makes a difference. But 10 little picures and one big picture made of the little pictures will take up the same amount of memory. But your system will actually handle many little pictures better than a very big one.

But before you go trying to reinvent the wheel try the imagelistview control from code project.

Its probably the most amazing free control i have ever seen, and its very customizable. check it out! http://www.codeproject.com/KB/list/imagelistview.aspx The guy said it can easily handle thousands of images, and just playing around with it, I open my entire MY Pictures folder containing over 1000 images and it handled it just fine, smooth scrolled and looks great.

Edited by Diamonddrake: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.