Reputation: 1873
I must create application, where it can be to load some image, apply some filters, draw few lines and save it. And I must do it using WPF. How I can draw on Image control in WPF? Or another control is better for it?
Upvotes: 0
Views: 5996
Reputation: 803
You can do this by adding InkCanvas to your page, add your image as Background Image of InkCanvas, and add save functionality.
Add "Save" button to your form and use following code to save it:
string newImagePath = "your file path";
var ms = new MemoryStream();
using (FileStream fs = new FileStream(newImagePath , FileMode.Create)
{
var rtb = new RenderTargetBitmap((int)inkImageCanvas.Width, (int)inkImageCanvas.Height, 96d, 96d, PixelFormats.Default);
rtb.Render(inkImageCanvas);
JpegBitmapEncoder encoder = new JpegBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(rtb));
encoder.Save(fs);
}
newImagePath
is the path to new file; inkImageCanvas
is your InkCanvas control.
This will save content of your inkCanval to jpg file.
Upvotes: 5