Windows Develop Bookmark and Share   
 index > Windows Forms General > ImageList increasing color depth.
 

ImageList increasing color depth.

            ImageList imageList1 = new ImageList();
            imageList1.ColorDepth = ColorDepth.Depth8Bit;
            Bitmap bitmap1 = new Bitmap(16, 16, PixelFormat.Format8bppIndexed);
            imageList1.Images.Add(bitmap1);
            PixelFormat pixelFormat1 = bitmap1.PixelFormat; //Format8bppIndexed
            PixelFormat pixelFormat2 = imageList1.Images[0].PixelFormat; //Format32bppArgb


Why is a 32bpp copy of the bitmap being made when I add to the ImageList? How can I make the ImageList use 8bpp images? This would greatly reduce the memory usage of my application, as it requires thousands of images in the ImageList of a ListView.

Thank you!
Gannon_____  Friday, October 02, 2009 1:22 PM
When you use the ImageList.Image[] getter, it creates a new bitmap from the image stored in the image list.  That new bitmap has the system default image format.  You must Dispose() it. 

Hans Passant.
  • Marked As Answer byGannon_____ Friday, October 02, 2009 6:51 PM
  •  
nobugz  Friday, October 02, 2009 3:44 PM
When you use the ImageList.Image[] getter, it creates a new bitmap from the image stored in the image list.  That new bitmap has the system default image format.  You must Dispose() it. 

Hans Passant.
  • Marked As Answer byGannon_____ Friday, October 02, 2009 6:51 PM
  •  
nobugz  Friday, October 02, 2009 3:44 PM
OK so are you implying that the above call to Add results in an 8bpp bitmap being added, and a 32bpp one only exists after the the call to Images[] ? I'm not really sure... Thanks.
Gannon_____  Friday, October 02, 2009 5:35 PM
Yes.  An 8bpp ImageList cannot store a 32bpp bitmap.  If you are running low on memory, make sure that you are disposing bitmaps properly.

Hans Passant.
nobugz  Friday, October 02, 2009 6:19 PM
Well that was dumb, but now I know. Yeah, the ImageList uses the same amount of memory as a a List<Image>. Now I wonder how the behavior of ImageList.Image[] would be considered correct or desirable by anyone. That's like, a bug, or something.
Gannon_____  Friday, October 02, 2009 7:17 PM
It is desirable, GDI+ has very poor support for indexed pixel formats.  You can load and save them, that's all.  Drawing is not possible.

Hans Passant.
nobugz  Friday, October 02, 2009 7:49 PM

You can use google to search for other answers

Custom Search

More Threads

• web service overriding the url property
• position one form accurately over another resizable form
• Printing in windows forms using .net 2.0
• adding Icons/Images to ListView(DetailView-Option)
• Delete Text From PDF File Using VB.NET
• Frames with windows forms
• Setting the 'startup' winform in a project?
• Problem while implementing software on LAN
• export child mdi into picture file
• I need a help. please help me