我有一个图像控件
<Image Name="img" HorizontalAlignment="Left" Height="400" Margin="499,155,0,0" VerticalAlignment="Top" Width="400"/>
我从相机拍摄照片
private async void TakePhoto_Click(object sender, RoutedEventArgs e)
{
CameraCaptureUI camera = new CameraCaptureUI();
camera.PhotoSettings.CroppedAspectRatio = new Size(4, 3);
var photo = await camera.CaptureFileAsync(CameraCaptureUIMode.Photo);
if (photo != null)
{
BitmapImage image = new BitmapImage();
image.SetSource(await photo.OpenAsync(FileAccessMode.Read));
img.Source = image;
}
}
现在我想将此图像从 img 控件保存到文件夹,但我不知道如何将图像从 img 控件解码到 StorageFile
private async void SaveFile_Click(object sender, RoutedEventArgs e)
{
FileSavePicker savePicker = new FileSavePicker();
savePicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
savePicker.FileTypeChoices.Add("jpeg image", new List<string>() { ".jpeg" });
savePicker.SuggestedFileName = "New picture";
StorageFile ff = await savePicker.PickSaveFileAsync();
if (ff != null)
{
await photo.MoveAndReplaceAsync(ff);
}
}
这是一个保存方法,我想从图像控件中保存图像
最佳答案
的
var photo =等待camera.CaptureFileAsync(CameraCaptureUIMode.Photo);
返回一个StorageFile。您所要做的就是将其保存到您想要的位置。
您可以通过多种方式实现这一目标。
示例:
StorageFolder localFolder = ApplicationData.Current.LocalFolder; // the app's local storage folder
await photo.MoveAsync(localFolder); //move the file to a new location
2.
//Create a new copy in a new location
await photo.CopyAsync(localFolder);
注意var photo == StorageFile photo
。这意味着在拍摄照片后,它的副本已经保存到本地存储上的临时位置(应用程序的 TempState 目录)。
关于c# - 如何从图像控制 Windows 8 应用程序将图像保存到文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23328817/