OutofMemory Exception (when cropping an Image)
<p>I am trying to crop an Image that coming from a byte array. Unlucky, I get the OutofMemory Exception in my cropImage function. this part show how I write it on a file.</p>

<pre><code>System.IO.MemoryStream ms = new System.IO.MemoryStream(strArr);

System.Drawing.Rectangle oRectangle = new System.Drawing.Rectangle();
oRectangle.X = 50;
oRectangle.Y = 100;
oRectangle.Height = 180;
oRectangle.Width = 240;

System.Drawing.Image oImage = System.Drawing.Image.FromStream(ms);
cropImage(oImage, oRectangle);
name = DateTime.Now.Ticks.ToString() + ".jpg";
System.IO.File.WriteAllBytes(context.Server.MapPath(name), strArr);
context.Response.Write("http://local.x.com/test/" + name);
</code></pre>

<p>and this part is my crop Image function which is obvious what it is doing..</p>

<pre><code>private static System.Drawing.Image cropImage(System.Drawing.Image img, System.Drawing.Rectangle cropArea)
{
    System.Drawing.Bitmap bmpImage = new System.Drawing.Bitmap(img);
    System.Drawing.Bitmap bmpCrop = bmpImage.Clone(cropArea,
    bmpImage.PixelFormat);
    return (System.Drawing.Image)(bmpCrop);
}
</code></pre>

<p>and this is how I construct my strArr</p>

<pre><code>System.IO.Stream str = context.Request.InputStream;
int strLen = Convert.ToInt32(str.Length);
byte[] strArr = new byte[strLen];
str.Read(strArr, 0, strLen);
string st = String.Concat(Array.ConvertAll(strArr, x =&gt; x.ToString("X2"))); // try 4
</code></pre>
