I have created a custom image class that overrides the onRender(DrawingContext dc)
method. In this method I use the drawingContext
to draw lines, dots and text into the image. Until then everything works. Now I want to save the image including the drawn elements in a folder. I have searched very long, but unfortunately found nothing suitable. Does anyone have an idea how I can save the image with the drawn elements as a bitmap?
Edit: This is what I have now:
cachedTargetBitmap = new RenderTargetBitmap((int)ActualWidth,
(int)ActualHeight, 96, 96, PixelFormats.Pbgra32);
cachedTargetBitmap.Render(this);
var encoder = new BmpBitmapEncoder();
BitmapFrame frame = BitmapFrame.Create(Image1.TargetBitmap);
encoder.Frames.Add(frame);
using (var stream = File.Create(string.Format("{0}\\Left.bmp", SavePath)))
{
encoder.Save(stream);
}
var encoder2 = new BmpBitmapEncoder();
BitmapFrame frame2 = BitmapFrame.Create(Image2.TargetBitmap);
encoder2.Frames.Add(frame2);
using (var stream = File.Create(string.Format("{0}\\Right.bmp", SavePath)))
{
encoder2.Save(stream);
}
I have 2 WPF Images and I draw lines, points and text on them. At saving the images as Bitmap, the first image is saved without the text, but with the points and lines and it is shifted to the right. The second image is saved completely black.