分享一个取得屏幕截图的代码,但是由于程序不能在后台运行,所以只能通过按钮或者菜单取得截图,然后把图片保存在相册中。这个是QQ群里的朋友分享的,我先留着。
public void CaptureScreen(object sender, EventArgs e) { WriteableBitmap bmp = new WriteableBitmap(480, 800); bmp.Render(App.Current.RootVisual, null); bmp.Invalidate(); MemoryStream stream = new MemoryStream(); bmp.SaveJpeg(stream, bmp.PixelWidth, bmp.PixelHeight, 0, 80); stream.Seek(0, SeekOrigin.Begin); MediaLibrary library = new MediaLibrary(); string filename = "ScreenShot_" + DateTime.Now.ToString("yyyy-MM-dd_hh:mm:ss"); library.SavePicture(filename, stream); stream.Close(); }