PDA

Click to See Complete Forum and Search --> : Help wanted clipping an image region


coolpjmartin
Feb 6th, 2009, 05:35 AM
Can someone please help me.

What I what to do is display a picture (image) and drawer a clip region using the mouse on a selected area on the image, this could be a retangle, square or a freehand shape, I think this could be done using path geometries and clip.

http://msdn.microsoft.com/en-us/library/ms751808(VS.85).aspx

Once I have marked the clip region, I then want to be able to save the selected clipped image as a new image (bitmap).

but I am not sure how to do this.

does anyone have any sample code, or suggestions.

this can be in either vb.net ot c#

Thanks

Negative0
Feb 6th, 2009, 05:08 PM
Have a look at this project, it seems to do what you are looking for:

http://www.codeproject.com/KB/WPF/ImageCropper.aspx

coolpjmartin
Feb 16th, 2009, 03:25 AM
Hi Thanks you for your reply. I have looked at the sugested examples, and can managed to display a clipped image, what I cannot work out is how to save that clipped image as a new bitmap image.

In the example below, if I create a clipped region around an image, how would I save the clipped bitmap.

The same if I created an image and added a pathgeometry to only show part of the image how to I save only the clipped part of the image.

// Sample 4

// Create the image to clip.

Image myImage = new Image();

Uri imageUri =

new Uri(@"C:\\Documents and Settings\\All Users\\Documents\My Pictures\\Sample Pictures\\Water lilies.jpg", UriKind.Relative);

myImage.Source = new BitmapImage(imageUri);

myImage.Width = 200;

myImage.Height = 150;

myImage.HorizontalAlignment = HorizontalAlignment.Left;


// Use an EllipseGeometry to define the clip region.

EllipseGeometry myEllipseGeometry2 = new EllipseGeometry();

myEllipseGeometry2.Center = new Point(100, 75);

myEllipseGeometry2.RadiusX = 100;

myEllipseGeometry2.RadiusY = 75;

myImage.Clip = myEllipseGeometry2;