C# Out of Memory when Creating Bitmap

前端 未结 6 1211
旧时难觅i
旧时难觅i 2020-12-09 19:41

I\'m creating an application (Windows Form) that allows the user to take a screenshot based on the locations they choose (drag to select area). I wanted to add a little \"pr

6条回答
  •  -上瘾入骨i
    2020-12-09 20:36

    MSDN explains that an OutOfMemoryException means

    rect is outside of the source bitmap bounds

    where rect is the first parameter to the Bitmap.Clone method.

    So check that the cropArea parameter is not larger than your image.

    In GDI+ an OutOfMemoryException does not really mean "out of memory"; the GDI+ error code OufOfMemory has been overloaded to mean different things. The reasons for this are historic and a well described by Hans Passant in another answer.

提交回复
热议问题