Lohit
Lohit

Reputation: 137

Issue while saving a Transparent Canvas in WPF

I have created a Grid in WPF with Red background. The Grid contains a transparent Canvas with some fixed size. Now while trying to export the Canvas as Image, I am getting an image with black background. But when there is some color in Canvas (say White or Red), I am getting a proper image. Can anybody please tell me why the image is generating with black background if a Canvas has a transparent color.

Example:

Grid grid = new Grid();
            grid.Background = new SolidColorBrush(Colors.Red);
            grid.Width = 500;
            grid.Height = 300;

            Canvas c = new Canvas();
            c.Width = 500;
            c.Height = 300;
            c.Background = new SolidColorBrush(Colors.Transparent);
            c.MouseLeftButtonUp += new MouseButtonEventHandler(c_MouseLeftButtonUp);

            grid.Children.Add(c);

            LayoutRoot.Children.Add(grid);

Inside MouseEvent handler of Canvas, I am saving it as jpg image.

Upvotes: 0

Views: 532

Answers (1)

Vinit Sankhe
Vinit Sankhe

Reputation: 19895

Inside MouseEvent handler of Canvas, I am saving it as jpg image.

Save it as PNG. These type of images are specialized in saving transparent backgrounds.

Upvotes: 2

Related Questions