如何在UWP应用程序中自动保存捕获的图像?

时间:2017-06-19 11:53:05

标签: image uwp save storagefile

我有这段代码:

CameraCaptureUI captureUI = new CameraCaptureUI();
captureUI.PhotoSettings.AllowCropping = false;
StorageFile photo = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);

单击捕获按钮时如何实现自动保存图像选项?

1 个答案:

答案 0 :(得分:0)

  

单击捕获按钮时如何实现自动保存图像选项?

如果我们不取消捕获,则包含捕获的照片的StorageFile会获得一个动态生成的名称并保存在我们应用的本地文件夹中,因此如果我们点击捕获按钮而不点击确认按钮,照片将自动保存在我们的应用程序的TempState文件夹中。

有关详细信息,请参阅Capture photos and video with Windows built-in camera UI

要更好地整理捕获的照片,您可能需要将文件移动到其他文件夹。请参阅以下示例,其中显示了如何将最新的捕获照片从TempState文件夹复制到LocalFolder。

例如:

CameraCaptureUI captureUI = new CameraCaptureUI();
captureUI.PhotoSettings.AllowCropping = false;
StorageFile photo = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);
Windows.Storage.StorageFolder localFolder = Windows.Storage.ApplicationData.Current.TemporaryFolder;
var allFiles =await localFolder.GetFilesAsync();
foreach (StorageFile item in allFiles.OrderByDescending(a => a.DateCreated))
    {
        StorageFolder destinationFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("ProfilePhotoFolder", CreationCollisionOption.OpenIfExists);
        await item.CopyAsync(destinationFolder, DateTimeOffset.Now.ToString("yyyyMMddHHmmssfff") + ".jpg", NameCollisionOption.ReplaceExisting);
        await item.DeleteAsync();
        return;
    }   
相关问题