MemoryStream memStream = new MemoryStream();
System.Windows.Media.Imaging.RenderTargetBitmap bmp = new System.Windows.Media.Imaging.RenderTargetBitmap((int)panel.ActualWidth, (int)panel.ActualHeight, 96d, 96d, System.Windows.Media.PixelFormats.Pbgra32);
bmp.Render(panel);
System.Windows.Media.Imaging.JpegBitmapEncoder encoder = new System.Windows.Media.Imaging.JpegBitmapEncoder();
encoder.Frames.Add(System.Windows.Media.Imaging.BitmapFrame.Create(bmp));
encoder.Save(memStream);
byte[] bt = memStream.ToArray();
memStream.Close(); memStream = new MemoryStream(bt);
BitmapImage biImg = new BitmapImage();
biImg.BeginInit();
biImg.StreamSource = memStream;
biImg.EndInit(); ImageBrush brush = new ImageBrush();
brush.ImageSource = (ImageSource)biImg;
imagePanel2.Background = brush;