catamount

Hi Expert,

I use WPF to draw some graphics on a Canvas. The background color of the canvas is white.

Then I use the following code to save to a png file.

The problem is that the background color becomes black when I use Paint to edit it.

How can I get white color for the bitmap backgroud so I can edit it using Paint

string path = @"d:\tmp.png";

System.IO.FileStream fs = new System.IO.FileStream(path, System.IO.FileMode.Create);

RenderTargetBitmap bmp = new RenderTargetBitmap((int)canvas1.Width, (int)canvas1.Height, 1 / 96, 1 / 96, PixelFormats.Pbgra32);

//canvas.ActualWidth and canvas.ActualHeight is zero when i have not add canvas to grid

bmp.Render(canvas1);

BitmapEncoder encoder = new TiffBitmapEncoder();

encoder.Frames.Add(BitmapFrame.Create(bmp));

encoder.Save(fs);

fs.Close();

Thanks a lot.



Re: Windows Presentation Foundation (WPF) Problem about bitmap in WPF

Jonathan.Peppers

I don't think that Paint opens pngs very well, it puts that black color on transparencies.

What does it look like if you open the picture in Adobe Photoshop or the standard Windows Picture Viewer

You may want to also check that your canvas's background truly is white rather than transparent.





Re: Windows Presentation Foundation (WPF) Problem about bitmap in WPF

catamount

Thanks Jonathan.

The problem is the background color of the canvas is not set.

I set it to white and it works well.

Thanks again.