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.
I can get to the point of creating the clipped image as in this example.
http://msdn.microsoft.com/en-us/library/ms751808(VS.85).aspx
but what I now want to do is save the 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 or c#
Thanks
Loading
Peter MartinPosted Feb 12, 2009, 6:26 AM
Hi Thanks you for your reply. In the example below, if I create a clipped region around an image, what would I pass in as the rendered bitmap.
The same if I created an image and added a pathgeometry to only show part of the image how to I passing 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;
Nipun TomarPosted Feb 11, 2009, 3:59 AM
// Create a render bitmap and push the surface to it
RenderTargetBitmap renderBitmap =new RenderTargetBitmap(
(int)size.Width,
(int)size.Height,
96d,
96d,
PixelFormats.Pbgra32);
renderBitmap.Render(yourui);
// Encode the image in the format selected
System.Windows.Media.Imaging.BitmapEncoder encoder = default
System.Windows.Media.Imaging.BitmapEncoder);
// Create a file stream for saving image
using (FileStream outStream = new FileStream(fileName, FileMode.Create))
{
switch (fileExtension.ToLower())
{
case ".jpg":
case ".jpeg":
encoder = new System.Windows.Media.Imaging.JpegBitmapEncoder();
break;
case ".png":
encoder = new System.Windows.Media.Imaging.PngBitmapEncoder();
break;
case ".gif":
encoder = new System.Windows.Media.Imaging.GifBitmapEncoder();
break;
case ".bmp":
encoder = new System.Windows.Media.Imaging.BmpBitmapEncoder();
break;
case ".tif":
case ".tiff":
encoder = new System.Windows.Media.Imaging.TiffBitmapEncoder();
break;
}
// push the rendered bitmap to it
encoder.Frames.Add(BitmapFrame.Create(renderBitmap));
// save the data to the stream
encoder.Save(outStream);
}