我正在使用Media Capture Api在我的windows store metro app中捕捉照片。 首先正确捕捉照片,然后将其保存在本地存储中,然后显示在位图图像中。这是我的代码。
Windows.Media.Capture.MediaCapture captureManager;
protected async override void OnNavigatedTo(NavigationEventArgs e)
{
captureManager = new MediaCapture();
await captureManager.InitializeAsync();
capturePreview.Source = captureManager;
await captureManager.StartPreviewAsync();
base.OnNavigatedTo(e);
}
private async void CapturePhoto_Click(object sender, RoutedEventArgs e)
{
try
{
ImageEncodingProperties imgFormat = ImageEncodingProperties.CreateJpeg();
string fileName = "" + fittingdetail.FittingDetailId + ".jpg";
StorageFile photoFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);
await captureManager.CapturePhotoToStorageFileAsync(imgFormat, photoFile);
BitmapImage bitmapToShow = new BitmapImage(new Uri(photoFile.Path));
imagePreivew.Source = bitmapToShow; // show image on screen inside Image control defined in XAML
}
catch (Exception ex)
{
throw ex;
}
}
此代码工作正常的问题是在第3次尝试后等图像预览未更新它显示最后拍摄的图像。我签入本地存储文件夹图像正在更新但不在位图图像中更新。我也在OnNavigatedFrom中处理对象,就像这样
public void Dispose()
{
if (captureManager != null)
{
captureManager.Dispose();
captureManager = null;
}
}
需要帮助我做错了什么。我不想在本地存储中复制文件我尝试使用独特的名称,它在那里工作正常。我还尝试在捕获文件后删除它,但之后没有显示预览。
答案 0 :(得分:0)
似乎某个特定路径的BitmapImage
个对象可能会被缓存,并且可能无法检测到更新。
我看到了几个选项:
BitmapImage
BitmapImage
URI属性Source