Out of memory when cropping a bitmap with .Clone()
<p>I am trying to automatically generate a thumbnail from an image uploaded by a user but I keep getting the exception "Out of memory".
From what I understand the out of memory exception is thrown when you specify a starting position or a width/height that's outside of the image but even if I do this</p>

<pre><code>var rct = new Rectangle(5, 5, 10, 10);
var whatever = bitmap.Clone(rct, bitmap.PixelFormat);
</code></pre>

<p>on an image that is 800x900 pixels I still get the "Out of memory" exception, I can't figure out what's wrong with it and I can't really get any good answers from other threads since everything regarding the OOM exception is just the mistake of going outside the image boundaries. 
Does anyone have an explanation or solution to this? </p>

<p>EDIT: A bit more context</p>

<p>The loop for the images.</p>

<pre><code>foreach (var blob in fileInfoList)
{
    var blockBlobName = CheckExistence(BaseBlobUrl, blob.FileName, blob.FileNameWithoutExtension);

    var image = new Image()
    {
        BlobUrl = Path.Combine(BaseBlobUrl, blockBlobName),
        FullName = blob.FileName,
        FileName = blob.FileNameWithoutExtension,
        BlockBlobName = blockBlobName,
        OwningOrganizationId = CurrentUser.UserOrganization.OrganizationId,
        ThumbnailUrl = CreateThumbnail(blob.File, blockBlobName),
        Name = "Whatever"
    };

    blobList.Add(image);

    RepositoryFactory.AzureStorageRepository.SaveImage(blob.File, blockBlobName, blob.ContentType, CurrentUser.UserOrganization.Organization.Id);
}
</code></pre>

<p>The method that is being called by each image in the list to generate the thumbnail.</p>

<pre><code>public string CreateThumbnail(byte[] b, string parentImageName)
    {
        Bitmap bmp;

        using (var ms = new MemoryStream(b))
        {
            bmp = new Bitmap(ms);
        }

        Bitmap thumbnail = bmp;

        Rectangle rect = new Rectangle(5, 5, 10, 10);

        if (bmp.Width &gt; bmp.Height)
            thumbnail = bmp.Clone(rect, bmp.PixelFormat);
        else if (bmp.Height &gt; bmp.Width)
            thumbnail = bmp.Clone(new Rectangle((bmp.Height/2) - (bmp.Width/2), 0, bmp.Width, bmp.Width), bmp.PixelFormat);

        byte[] bmpArray = new byte[0];

        using (var ms = new MemoryStream())
        {
            finalCrop.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
            ms.Close();

            bmpArray = ms.ToArray();
        }

        var name = "Thumbnail_" + parentImageName;

        RepositoryFactory.AzureStorageRepository.SaveThumbnail(bmpArray, name, "jpg/image", CurrentUser.UserOrganization.Organization.Id);

        return BaseBlobUrl + "thumbnails/" + name;


    }
</code></pre>