Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,755 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
This is my Code:
<Grid>
<Image x:Name="img" Source="xxx.png" Stretch="Fill">
**<Image.Clip>
<PathGeometry>
<PathFigure StartPoint="0,0">
<LineSegment Point="150,50"></LineSegment>
<LineSegment Point="150,200"></LineSegment>
<BezierSegment Point1="150,200" Point2="100,100" Point3="0,0"></BezierSegment>
</PathFigure>
</PathGeometry>
</Image.Clip>**
</Image>
</Grid>
l input a Image and did some Clip with PathGeometry,now l want save the new Image as bitmap?
How Can I do that??
You can use the below code to save a image to a bitmap:
private void SaveToBit()
{
RenderTargetBitmap rtb = new RenderTargetBitmap(400,400, 96d, 96d, System.Windows.Media.PixelFormats.Default);
rtb.Render(img);
var crop = new CroppedBitmap(rtb, new Int32Rect(50, 50, 250, 250));
BitmapEncoder pngEncoder = new PngBitmapEncoder();
pngEncoder.Frames.Add(BitmapFrame.Create(crop));
using (Stream s = new MemoryStream())
{
pngEncoder.Save(s);
Bitmap myBitmap = new Bitmap(s);
}
}
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.