我到处寻找,但在我拍下照片后无法找到保存照片的方法。我使用Windows 8媒体捕获,捕获后,我在我的页面上显示它。但是不知道如何将它保存到特定的地方。
这就是我拍照的方式,非常经典:
private async void Camera_Clicked(object sender, TappedRoutedEventArgs e)
{
TurnOffPanels();
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;
appSettings[photoKey] = photo.Path;
}
}
这就是我在拍摄之后重新加载它的方式:
private async Task ReloadPhoto(String photoPath)
{
StorageFile photo = await StorageFile.GetFileFromPathAsync(photoPath);
BitmapImage bmp = new BitmapImage();
using (IRandomAccessStream stream = await photo.OpenAsync(FileAccessMode.Read))
{
bmp.SetSource(stream);
}
}
有没有人知道如何保存照片?
问候。
答案 0 :(得分:0)
使用FileSavePicker,例如:
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);
}
照片是您从相机获取的StorageFile
答案 1 :(得分:0)
我试过,但没有成功。我现在可以保存,但我什么都不保存。我想我用ImageStream失败了,我不明白。
这是没有读者的代码。对不起,我是Windows 8 C#的初学者
private async void save_Click_1 (object sender, RoutedEventArgs e)
{
FileSavePicker savePicker = new FileSavePicker();
savePicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
savePicker.FileTypeChoices.Add("jpeg", new List<string>() { ".jpeg" });
savePicker.SuggestedFileName = "New picture";
StorageFile ff = await savePicker.PickSaveFileAsync();
if (ff != null)
{
}
}
答案 2 :(得分:0)
private async void btnSave(object sender, RoutedEventArgs e)
{
//ImageTarget.Source = await ResizeWritableBitmap(m_bitmap, 800, 800);
if (m_bitmap == null)
return;
Windows.Storage.StorageFile filename = await GetSaveLocation();
if (filename == null)
return;
IRandomAccessStream filestream = await filename.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite);
BitmapEncoder encode = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, filestream);
byte []pixelbuff;
var stream = m_bitmap.PixelBuffer.AsStream();
pixelbuff = new byte[stream.Length];
await stream.ReadAsync(pixelbuff, 0, pixelbuff.Length);
encode.SetPixelData(BitmapPixelFormat.Rgba8, BitmapAlphaMode.Straight,(uint) m_bitmap.PixelWidth
,(uint) m_bitmap.PixelHeight, 96.0, 96.0, pixelbuff);
await encode.FlushAsync();
await filestream.FlushAsync();
filestream.Dispose();
}