I\'m suffering from an OutOfMemoryException when obtaining an Image from an ImageList I\'ve been unable to find an appropriate solution to the problem.
I\'ve got a C
Are you disposing graphics
? Also, it you dispose your image like you mentioned then you would need to make sure it is taken out of the ImageList or you will cause more issues. What what format are the images?
In general when you get out of memory issues when images are involved, your issue will be either some method does not like some image format, or 9/10 times, you misunderstood the lifecycle of one of the graphic objects.
Graphics
usage and put them in using
blocks.Image
life cycle and be careful with copying them, disposing them, closing underlying streams, etc.EDIT:
Here is the best option I can find, use ImageList.Draw(graphics, x, y, width, height, index)
. This will use the internal handle instead of creating a copy of the image.