我正在尝试使用 C# 为 Windows 8 开发相机应用程序。
我的代码:
public string newFilename { get; set; }
private StorageFile photo;
protected async override void OnNavigatedTo(NavigationEventArgs e)
{
t1.Text = System.DateTime.Now.Date.ToString();
CameraCaptureUI cam = new CameraCaptureUI();
cam.PhotoSettings.CroppedAspectRatio = new Size(6, 4);
var photo = await cam.CaptureFileAsync(CameraCaptureUIMode.Photo);
//StorageFile photo = await cam.CaptureFileAsync(CameraCaptureUIMode.Photo);
//if (photo != null)
//{
// var targetFile = await ApplicationData.Current.LocalFolder.CreateFileAsync("IMAGE11.jpg");
// if (targetFile != null)
// {
// await photo.MoveAndReplaceAsync(targetFile);
// }
//}
if (photo != null)
{
IRandomAccessStream stream = await photo.OpenAsync(FileAccessMode.Read);
var bitmap = new BitmapImage();
bitmap.SetSource(await photo.OpenAsync(FileAccessMode.ReadWrite));
BitmapImage img = new BitmapImage();
im1.Source = bitmap;
//StorageFile sample = await localfolder.CreateFileAsync("img.png", CreationCollisionOption.GenerateUniqueName);
}
}
private async void Button_Click_1(object sender, RoutedEventArgs e)
{
if (photo != null)
{
await photo.MoveAsync(ApplicationData.Current.LocalFolder,newFilename);
}
}
我的应用程序显示捕获的相机图像。
我的问题是:如何将捕获的相机图像存储在本地文件夹中?