【发布时间】:2013-12-13 08:24:46
【问题描述】:
我正在尝试在加载“我的应用”时截取屏幕截图,而无需任何用户交互。
我的代码是这样的
public MainPage()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(ApplicationBarIconButton);
}
private void ApplicationBarIconButton(object sender, EventArgs e)
{
var fileName = String.Format("WmDev_{0:}.jpg", DateTime.Now.Ticks);
WriteableBitmap bmpCurrentScreenImage = new WriteableBitmap((int)this.ActualWidth, (int)this.ActualHeight);
bmpCurrentScreenImage.Render(LayoutRoot, new MatrixTransform());
bmpCurrentScreenImage.Invalidate();
SaveToMediaLibrary(bmpCurrentScreenImage, fileName, 100);
MessageBox.Show("Captured image " + fileName + " Saved Sucessfully", "WmDev Capture Screen", MessageBoxButton.OK);
currentFileName = fileName;
}
public void SaveToMediaLibrary(WriteableBitmap bitmap, string name, int quality)
{
using (var stream = new MemoryStream())
{
// Save the picture to the Windows Phone media library.
bitmap.SaveJpeg(stream, bitmap.PixelWidth, bitmap.PixelHeight, 0, quality);
stream.Seek(0, SeekOrigin.Begin);
new MediaLibrary().SavePicture(name, stream);
}
}
我收到以下错误:
【问题讨论】:
-
异常发生在哪一行?
-
at... new MediaLibrary().SavePicture(name, stream);
-
您是否已将 ID_CAP_MEDIALIB_PHOTO 功能添加到应用的清单中? stackoverflow.com/questions/14387294/…
标签: c# xaml windows-phone-7 windows-phone-8