简体   繁体   English

Windows 8 C#将相机的图片保存在本地存储中

[英]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.

相关问题 如何从我的Windows Phone 8应用程序(XAML和C#)访问相机并将拍摄的照片保存在确定的文件夹中? - How to access the camera from my Windows Phone 8 app (XAML and C#) and save the taken picture in a determined folder? 如何在图片上绘制文本并将其保存在 Windows 手机 c# 应用程序中? - how to draw text on picture and save it on windows phone c# app? Windows8 App by C#如何将Canvas保存为图片? - Windows8 App By C# How to save a Canvas as a picture? 将列表保存并检索到本地存储中(Windows Phone 8.1&C#) - Saving and retrieving list to a local storage (Windows Phone 8.1 & C#) 将联系人保存在Windows Phone 7 C#的隔离存储中 - save Contact in isolated storage in windows phone 7 c# 从现有的相机应用程序Windows Phone 8.1运行时C中获取图片 - get Picture from exising camera app Windows Phone 8.1 runtime c# Windows Mobile:使用C#的手机摄像头 - Windows Mobile: using phone's camera with C# Windows MobilePhone的摄像头应用程序(C#) - Windows Mobile- Phone's camera application (C#) 如何使用C#将Instagram用户图片保存到本地计算机 - How to save an Instagram user Picture to my local machine using C# C#将图片文件保存到RAM - c# save a picture file to ram
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM