【问题标题】:How save photo capture windows 8 c# metro app?如何保存照片捕获 windows 8 c# Metro 应用程序?
【发布时间】:2013-01-28 16:18:30
【问题描述】:

我到处寻找,但在拍摄照片后找不到如何保存照片。我使用 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);
            }

    }

有人知道如何保存照片吗?

问候。

【问题讨论】:

    标签: c# windows-8 microsoft-metro photo capture


    【解决方案1】:

    使用 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);
      }
    

    photo 是一个 StorageFile,你从相机中获得

    【讨论】:

    • 我试试这个,但不明白你的 imageStream 到底是什么?
    • ImageStream 是一个带有捕获的相机图像的流,在您的代码中:IRandomAccessStream stream = await photo.OpenAsync(...),但是现在当我查看它时,我们可以直接使用 StorageFile 并复制它内容。将更新我的答案
    【解决方案2】:

    我试过了,但没有成功。我现在可以保存,但我什么也没保存。我想我不明白的 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)
            {
            }
        }
    

    【讨论】:

      【解决方案3】:

      也许是这样

            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();
          }
      

      【讨论】:

        猜你喜欢
        • 2013-02-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-04-03
        • 1970-01-01
        相关资源
        最近更新 更多