【发布时间】:2014-01-16 10:42:49
【问题描述】:
我正在构建一个需要使用网络摄像头拍照并将其保存到本地磁盘的应用程序,到目前为止我有这个:
async private void CapturePhoto_Click(object sender, RoutedEventArgs e)
{
Windows.Storage.StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
ImageEncodingProperties imgFormat = ImageEncodingProperties.CreateJpeg();
// create storage file in local app storage
StorageFile file = await localFolder.CreateFileAsync("TestPhoto.jpg", CreationCollisionOption.GenerateUniqueName);
StorageFile localFile = await localFolder.CreateFileAsync("webcamPhotoTest.jpg", CreationCollisionOption.ReplaceExisting);
// take photo
// save to app storage
await captureManager.CapturePhotoToStorageFileAsync(imgFormat, file);
// save to local storage
await captureManager.CapturePhotoToStorageFileAsync(imgFormat, localFile);
// Get photo as a BitmapImage
BitmapImage bmpImage = new BitmapImage(new Uri(file.Path));
// imagePreview is a <Image> object defined in XAML
imagePreview.Source = bmpImage;
}
我可以将 jpg 图像同时保存到应用存储和本地存储,但我需要能够 a) 指定保存路径 b) 这样做不需要用户交互(例如 windows 保存文件提示)
Windows 8 应用程序不支持 System.Drawing,这使事情变得复杂。我发现的大多数答案要么是使用 System.Drawing 功能,要么是 Windows 的保存文件提示。
【问题讨论】:
-
您知道要保存在哪里吗?也许看这里:stackoverflow.com/questions/4161359/save-bitmapimage-to-file
-
是的,但现在任何地方都可以。以后可以随时更改路径。要点是能够指定它。您提供的链接似乎是关于下载和保存,而不是从应用程序中保存。
标签: c# windows-store-apps