<图片>———屏幕截图、图片保存至图片库
屏幕截图并保存至图片库代码:
1 WriteableBitmap bmp = new WriteableBitmap(480, 800); 2 bmp.Render(App.Current.RootVisual, null); 3 bmp.Invalidate(); 4 MemoryStream stream = new MemoryStream(); 5 bmp.SaveJpeg(stream, bmp.PixelWidth, bmp.PixelHeight, 0, 80); 6 stream.Seek(0, SeekOrigin.Begin); 7 MediaLibrary library = new MediaLibrary(); 8 string filename = "BarCode_lxh_" + DateTime.Now.ToString("yyyy-MM-dd_hh:mm:ss"); 9 library.SavePicture(filename, stream); 10 stream.Close();
再分享一下网上的段代码:
private void button1_Click(object sender, RoutedEventArgs e) { string tempJPEG = "WhiteParis.png"; var store = IsolatedStorageFile.GetUserStoreForApplication(); if (store.FileExists(tempJPEG)) { store.DeleteFile(tempJPEG); } IsolatedStorageFileStream fileStream = store.CreateFile(tempJPEG); StreamResourceInfo sri = null; Uri uri = new Uri("Images/WhiteParis.png", UriKind.Relative); sri = Application.GetResourceStream(uri); BitmapImage bitmap = new BitmapImage(); bitmap.SetSource(sri.Stream); WriteableBitmap wbmp = new WriteableBitmap(bitmap); Extensions.SaveJpeg(wbmp, fileStream, wbmp.PixelWidth, wbmp.PixelHeight, 0, 85); fileStream .Close (); fileStream = store.OpenFile(tempJPEG, FileMode.Open, FileAccess.Read); MediaLibrary mediaLibrary = new MediaLibrary(); Picture pic = mediaLibrary.SavePicture("WhiteParis.png", fileStream); fileStream.Close(); }