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);
}
它正在工作。這張照片是由照相機定義爲照片的文件類型是storageFile,我沒有定義它的類型。這也適用:await photo.MoveAsync(KnownFolders.PicturesLibrary,「MyPhoto」+「.jpeg」,NameCollisionOption.GenerateUniqueName); DesiredPhotoName的意思是「Name」+「.jpeg」謝謝 – MilkBottle
最好使用'photo.FileType',因爲某些相機可能會提供不同的格式。所以我們不應該_hardcode_格式。 – Xyroid
謝謝。但是,我怎麼知道照相機定義的照片文件類型?在哪裏設置照片文件類型?我認爲它是預定義的,如JPG。 Thans – MilkBottle