我想每 10 秒捕获一次图像。为此,我将使用 Timer 类,它将运行以下代码:
async private void captureImage()
{
capturePreview.Source = captureManager;
await captureManager.StartPreviewAsync();
ImageEncodingProperties imgFormat = ImageEncodingProperties.CreateJpeg();
// create storage file in local app storage
StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync(
"TestPhoto.jpg",
CreationCollisionOption.GenerateUniqueName);
// take photo
await captureManager.CapturePhotoToStorageFileAsync(imgFormat, file);
// Get photo as a BitmapImage
BitmapImage bmpImage = new BitmapImage(new Uri(file.Path));
// imagePreivew is a <Image> object defined in XAML
imagePreivew.Source = bmpImage;
await captureManager.StopPreviewAsync();
//send file to server
sendHttpReq();
await file.DeleteAsync(StorageDeleteOption.PermanentDelete);
}
目前我在点击按钮时调用上面的函数,
我想在图像传输后删除文件,因为我会将其发送到 Web 服务器。但是,我没有看到 imagePreivew 在按钮单击时得到更新,而当我不删除文件时,我每次按下按钮时都会看到 imagePreivew 发生变化。我也尝试了 CreationCollisionOption.ReplaceExisting 但仍然面临同样的问题。每次计时器执行任务时创建新文件会浪费大量内存。怎么删除文件???