[英]Windows 8 c# save a camera's picture on local storage
I'm new to C# and I want to create an application metro who can take picture and save themself in localstorage. 我是C#的新手,我想创建一个可以拍摄照片并将其保存在本地存储中的应用程序Metro。 I know, i need to use isolated storage but i really don't understand how to use it for image.
我知道,我需要使用隔离存储,但是我真的不明白如何使用它存储图像。 I saw a lot of examples for string but not for picture.
我看到了很多字符串示例,但没有图片示例。
If anyone know how to do it ? 如果有人知道怎么做? Actually i take a picture and i ask the user to record it where he wants.
实际上,我拍了一张照片,然后请用户将其记录在他想要的位置。 But I want an auto record after the user take the picture.
但是我想在用户拍照后自动记录。 This my code for the moment :
这是我目前的代码:
private async void Camera_Clicked(object sender, TappedRoutedEventArgs e)
{
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;
FileSavePicker savePicker = new FileSavePicker();
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);
}
}
}
All what you need to do is to replace File Picker logic with retrieving of StorageFile object in Local folder, for example like this: 您需要做的就是用检索本地文件夹中的StorageFile对象替换File Picker逻辑,例如:
private async void Camera_Clicked(object sender, TappedRoutedEventArgs e)
{
CameraCaptureUI camera = new CameraCaptureUI();
camera.PhotoSettings.CroppedAspectRatio = new Size(16, 9);
StorageFile photo = await camera.
CaptureFileAsync(CameraCaptureUIMode.Photo);
if (photo != null)
{
var targetFile = await ApplicationData.Current.LocalFolder.CreateFileAsync("some_file_name.jpg");
if (targetFile != null)
{
await photo.MoveAndReplaceAsync(targetFile);
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.