ImageList / Image OutOfMemoryException

后端 未结 2 1258
轻奢々
轻奢々 2021-01-06 05:25

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

2条回答
  •  再見小時候
    2021-01-06 06:16

    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.

    • Check all your Graphics usage and put them in using blocks.
    • Check your Image life cycle and be careful with copying them, disposing them, closing underlying streams, etc.
    • Load up a memory manager (VS2008 has one built in) and see what is not getting cleaned up nicely.

    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.

提交回复
热议问题