拍摄一张照片,并将其保存到Windows 8 Metro风格的应用程序中的磁盘上

本文关键字:风格 Metro 应用程序 磁盘 Windows 一张照片 保存 | 更新日期: 2023-09-27 18:23:46

我可以拍照,但在保存到KnownFolders时遇到问题。是的,我已经在Package.appxmanifest.中声明了图片库访问能力

var ui = new CameraCaptureUI();
ui.PhotoSettings.CroppedAspectRatio = new Size(4, 3);
StorageFile file = await ui.CaptureFileAsync(CameraCaptureUIMode.Photo);
if (file != null)
{
    var stream = await file.OpenAsync(FileAccessMode.Read);
    var bitmap = new BitmapImage();
    bitmap.SetSource(stream);
    Photo.Source = bitmap;
    StorageFolder storageFolder = KnownFolders.PicturesLibrary;
    var result = await file.CopyAsync(storageFolder, "tps.jpg");
}

代码在最后一行停止。我做错了什么?

拍摄一张照片,并将其保存到Windows 8 Metro风格的应用程序中的磁盘上

我认为您还需要声明文件类型!

  • 在"声明"选项卡中,从"可用"中选择"文件类型关联"声明,然后单击"添加"
  • 在"特性"下,将"名称"特性设置为image
  • 在支持的文件类型框中,通过在FileType字段中输入.jpg