0
我正在使用Media Capture Api捕獲Windows Store中的地圖應用中的照片。 正確的照片捕捉首先它保存在本地存儲,然後顯示在位圖圖像。這是我的代碼。在Windows應用商店應用中捕獲圖片後第3次未能正常工作
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;
}
}
此代碼工作正常的問題是,第三次嘗試後,等圖像預覽不更新它顯示最後的圖像捕獲。我檢查本地存儲文件夾中的圖像正在更新,但未在位圖圖像中更新。我也在像OnNavigatedFrom這樣處理對象
public void Dispose()
{
if (captureManager != null)
{
captureManager.Dispose();
captureManager = null;
}
}
需要幫助我做錯了什麼。我不想在本地存儲中重複文件我試圖用獨特的名稱在那裏工作。我也嘗試刪除文件後,它被捕獲,但沒有預覽顯示。
您是否嘗試過每次都使用不同的文件名? –
是的,它工作的很好,但它填充本地存儲,即使用戶不保存到數據庫。 –