public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); this.Loaded += MainWindow_Loaded; } void MainWindow_Loaded(object sender, RoutedEventArgs e) { Canvas canvas1 = new Canvas(); canvas1.Width = 300; canvas1.Height = 300; canvas1.Background = Brushes.Red; canvas1.UpdateLayout(); Image image = new Image(); RenderTargetBitmap bmp = new RenderTargetBitmap((int)canvas1.Width, (int)canvas1.Height, 0, 0, PixelFormats.Pbgra32); bmp.Render(canvas1); image.Source = bmp; Canvas canvas2 = new Canvas(); canvas2.Width = 300; canvas2.Height = 300; canvas2.Background = Brushes.Black; canvas2.Children.Add(image); this.Content = canvas2; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)