I am getting a System.OutOfMemoryException when I try storing a portions of an image to a bitmap using a loop. I do not think it's because the image is too big because another version of my code uses multiple of the same image but without a bitmap. Here is what I got:
Bitmap map = new Bitmap(img);
for (int i = 0; i < 4; i++) {
for (int y = 0; y < 4; y++) {
// Clone a portion of the Bitmap object.
Rectangle rec = new Rectangle(i*(img.Width / 4),
y*(img.Height / 4),
img.Width,//image width
img.Height);
PixelFormat format = map.PixelFormat;
Bitmap clone = null;
try {
clone = map.Clone(rec, format);
} catch (OutOfMemoryException e)