0

我使用下面的代码来捕获照片,但不确定如何将其保存在图片库或图片库中的文件夹中。非常感谢您对此的帮助。

CameraCaptureUI camera = new CameraCaptureUI();
camera.PhotoSettings.CroppedAspectRatio = new Size(16, 9);
StorageFile photo = await camera.CaptureFileAsync(CameraCaptureUIMode.Photo);


if (photo != null)
{
  BitmapImage bmp = new BitmapImage();
  IRandomAccessStream stream = await photo.OpenAsync(FileAccessMode.Read);
  bmp.SetSource(stream);
  ImageSource.Source = bmp;
  ImageSource.Visibility = Visibility.Visible;

  StorageFolder storageFolder = KnownFolders.PicturesLibrary;

??? not sure :
     var imagefile = await KnownFolders.PicturesLibrary.CreateFileAsync("MyPhoto.jpeg", CreationCollisionOption.ReplaceExisting);

   photo.CopyAsync(storageFolder,imagefile);

  }
4

1 回答 1

2

干得好。您必须在清单中设置相机和图片库访问能力。

CameraCaptureUI camera = new CameraCaptureUI();
camera.PhotoSettings.CroppedAspectRatio = new Size(16, 9);
StorageFile photo = await camera.CaptureFileAsync(CameraCaptureUIMode.Photo);

//By default the photo will be stored at location
//%localappdata%\Packages\APP_PACKAGE_ID\TempState

if (photo != null)
{
    //await photo.MoveAsync(KnownFolders.PicturesLibrary);
    //OR
    await photo.MoveAsync(KnownFolders.PicturesLibrary, "DesiredPhotoName" + photo.FileType, NameCollisionOption.GenerateUniqueName);
}
于 2013-08-28T10:48:54.107 回答