I have D3DImage _di that use to draw a background of Wpf Border in the form of a Brush. The Image is rendered fine but i want to save the Brush to png file on disk even if the Brush is not showed on the View.
I tried as below to save it to disk but all i got is black image:
_receivedBrush =(Brush)new ImageBrush((ImageSource)_di)
RenderTargetBitmap bmpCopied = new RenderTargetBitmap(350, 174, 96, 96, PixelFormats.Default);
DrawingVisual dv = new DrawingVisual();
using (DrawingContext dc = dv.RenderOpen())
{
dc.DrawRectangle(_receivedBrush, null, new Rect(new Point(), new Size(350, 174)));
}
bmpCopied.Render(dv);
MemoryStream mse = new MemoryStream();
BmpBitmapEncoder mem = new BmpBitmapEncoder();
mem.Frames.Add(BitmapFrame.Create(bmpCopied));
mem.Save(mse);
File.WriteAllBytes(@"g:\brush.png", mse.ToArray());
mse.Close();
Thanks in advance,