End Google Ads 201810 - BS.net 01 --> Hi all,

I am trying to crop an image based on a transparent panel that I have placed on the image. The transparent panel is placed on the image control based on certain coordinates (selected by a user based on mouse events). This works fine.

Now I want to try and crop the piece where the transparent panel is located on the image, but I keep receiving an exception: OutOfMemoryException => rect is outside of the source bitmap bounds.

But why is this happening? (note: The image Bounds value of X and Y is 0 and the transparent panel width and height is in bounds with the height and width of the image) The transparent panel is located within the picturebox, shouldn't it be able to get the correct position ??
Here is the code ...



...
TransparentPanel tmpPnl = e.ClickedItem.Tag as TransparentPanel;
Rectangle rec = tmpPnl.Bounds;
Bitmap bmpImage = new Bitmap(base.Image);
Bitmap bmpCrop = bmpImage.Clone(rec, bmpImage.PixelFormat); // exception occurs here
...



FYI

That “out of memory” exception appears when you attempt to crop a piece of the image outside itself.

Eg: If the image is 800×600 and you go:

Bitmap b = CropBitmap(myPic, 700, 500, 200, 200);

That’ll try select from 700×500 to 900×700, which does not actually exist.


Many thanks in advance
Kind regards,



The only programmers that are better C# programmers, are those who look like this ->


Programm3r

My Blog: ^_^

modified on Wednesday, September 9, 2009 6:01 AM