-
Notifications
You must be signed in to change notification settings - Fork 82
Description
This is an excellent and versatile control, I am using the ImageBoxEx code (v1.1) extending the ImageBox v1.4 found in the latest NuGet package. I am using ImageBoxEx because I want to add some image editing capabilities to transform my image.
So far I get my image displayed, the selection regions are displayed and can be resized and moved. At some point though, I want to CROP the image using the SelectionRegion rectangle. I have the code to do the cropping which I have tested in a regular (stock) PictureBox control; However, this does not seem to be working with the ImageBox/Ex controls.
Basically I do this:
using (ImageProcessor imgProc = new ImageProcessor(imageBox1.Image))
{
Rectangle rect = Rectangle.Round(imageBox1.SelectionRegion);
imageBox1.SelectNone();
imgProcessor.Crop(rect);
imageBox1.Image = imgProcessor.CurrentImage;
}
where the Crop method looks like this:
public void Crop(Rectangle r)
{
Bitmap temp = (Bitmap)_currentBitmap; // this is where the bitmap was placed by the constructor
Bitmap bmap = (Bitmap)temp.Clone();
if (r.X + r.Width > _currentBitmap.Width)
r.Width = _currentBitmap.Width - r.X;
if (r.Y + r.Height > _currentBitmap.Height)
r.Height = _currentBitmap.Height - r.Y;
_currentBitmap = (Bitmap)bmap.Clone(r, bmap.PixelFormat);
}
But after I do that the imageBox image gets cleared from the ImageBoxEx control. If I eliminate the using() then the image remains the same as if I had not cropped it.