標籤:
匯入以下命名空間:
using System.Windows.Media.Imaging;using System.IO;using Microsoft.Xna.Framework.Media;
全部代碼如下:
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(); Dispatcher.BeginInvoke(() => { PictureCollection picCollection = library.Pictures; foreach (Picture item in picCollection) { if (item != null) { BitmapImage bitmap = new BitmapImage(); bitmap.SetSource(item.GetImage()); } } });}
轉自:http://terryblog.blog.51cto.com/1764499/551752/
Windows Phone截取當前螢幕儲存映像的代碼