Note that there are some explanatory texts on larger screens.

plurals
  1. POC# Out of Memory when Creating Bitmap
    text
    copied!<p>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 "preview pane" thats zoomed in so the user can select the area they want more precisely (larger pixels). On a mousemove event i have a the following code...</p> <pre><code>private void falseDesktop_MouseMove(object sender, MouseEventArgs e) { zoomBox.Image = showZoomBox(e.Location); zoomBox.Invalidate(); bmpCrop.Dispose(); } private Image showZoomBox(Point curLocation) { Point start = new Point(curLocation.X - 50, curLocation.Y - 50); Size size = new Size(100, 90); Rectangle rect = new Rectangle(start, size); Image selection = cropImage(falseDesktop.Image, rect); return selection; } private static Bitmap bmpCrop; private static Image cropImage(Image img, Rectangle cropArea) { if (cropArea.Width != 0 &amp;&amp; cropArea.Height != 0) { Bitmap bmpImage = new Bitmap(img); bmpCrop = bmpImage.Clone(cropArea, bmpImage.PixelFormat); bmpImage.Dispose(); return (Image)(bmpCrop); } return null; } </code></pre> <p>The line that fails and has the Out of Memory exception is:</p> <pre><code>bmpCrop = bmpImage.Clone(cropArea, bmpImage.PixelFormat); </code></pre> <p>Basically what this does is it takes a 100x90 rectangle around the mouse pointer and pulls that into the zoomBox, which is a picturebox control. However, in the process, i get an Out Of Memory error. What is it that i am doing incorrectly here?</p> <p>Thanks for your assistance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload