如何保存照片捕获窗口 8 C# 地铁应用程序

本文关键字:窗口 应用程序 地铁 照片 何保存 保存 | 更新日期: 2023-09-27 17:56:16

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

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

问候。

如何保存照片捕获窗口 8 C# 地铁应用程序

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

照片是你从相机得到的存储文件

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

也许这个

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