簡體   English   中英

如何保存照片捕獲Windows 8 C#Metro應用程序?

[英]How save photo capture windows 8 c# metro app?

我四處張望,但捕捉到照片后卻找不到如何保存照片。 我使用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);
            }

    }

有誰知道如何保存照片?

問候。

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

照片是從相機獲取的StorageFile

我嘗試過,但沒有成功。 我現在可以保存,但是我什么也不會保存。 我想我不理解的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();
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM