Attempting to clone part of an image causes the OutOfMemoryException to be thrown.
The line that causes the error is:
TileImage = TileFileImage.Clone(CloneRect, TileFileImage.PixelFormat);
TileFileImage
is 271x271px in size.
CloneRect
's upper left corner is at (186, 16) and its lower right corner is at (202, 32) before the exception is thrown.
Both TileImage
and TileFileImage
are Bitmap
s.
CloneRect
can never be larger than 271x271px.
Logic in the method the above statement is in prevents the rectangle from exceeding the bounds of the image.
How do I fix this?
UPDATE:
I checked over my logic and found the problem.
Some indices could end up outside the source Bitmap
.