1

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

    }

有谁知道如何保存照片?

问候。

4

3 回答 3

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

photo 是您从相机获得的 StorageFile

于 2013-01-28T16:55:52.913 回答
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)
        {
        }
    }
于 2013-01-30T15:42:02.727 回答
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();
    }
于 2013-04-25T21:44:57.760 回答