日期:2014-05-20 浏览次数:20922 次
SaveWindowContent(this, "c:\\tmp.bmp"); private void SaveWindowContent(Window source, string fileName) { FrameworkElement elem = source.Content as FrameworkElement; RenderTargetBitmap targetBitmap = new RenderTargetBitmap( (int)elem.ActualWidth, (int)elem.ActualHeight, 96d, 96d, PixelFormats.Default); targetBitmap.Render(source); BmpBitmapEncoder encoder = new BmpBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(targetBitmap)); // save file to disk using (FileStream fs = File.Open(fileName, FileMode.OpenOrCreate)) { encoder.Save(fs); } }