如何在UWP应用程序中执行MediaCapture但不在本地计算机中存储

时间:2017-11-06 04:56:20

标签: camera uwp

我正在开发一个带摄像头功能的UWP应用程序,我研究了这组代码,
https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/CameraStarterKit

并在我的应用程序上成功开发了相机功能。但是,在我的应用程序中,我希望不将图片存储到我的本地计算机,因为该应用程序实际上就像一个自助服务终端系统,每个人都将使用同一台机器来拍照。

我计划做的实际上是允许用户通过自助服务终端系统将他们拍摄的照片发送到他们自己的电子邮件地址。当他们拍摄照片时,将显示预览,并且仅当用户想要发送图片时,图片才会"保存"

take picture

拍照功能的代码如下:

rivate async Task TakePhotoAsync()
    {

        var stream = new InMemoryRandomAccessStream();

        Debug.WriteLine("Taking photo...");
        await _mediaCapture.CapturePhotoToStreamAsync(ImageEncodingProperties.CreateJpeg(), stream);

        try
        {
            var file = await _captureFolder.CreateFileAsync("SimplePhoto.jpg", CreationCollisionOption.GenerateUniqueName);
            Debug.WriteLine("Photo taken! Saving to " + file.Path);

            var photoOrientation = CameraRotationHelper.ConvertSimpleOrientationToPhotoOrientation(_rotationHelper.GetCameraCaptureOrientation());

            await ReencodeAndSavePhotoAsync(stream, file, photoOrientation);
            Debug.WriteLine("Photo saved!");


        }
        catch (Exception ex)
        {
            // File I/O errors are reported as exceptions
            Debug.WriteLine("Exception when taking a photo: " + ex.ToString());
        }

    }

要获得图片的预览,请执行以下操作:

private async Task GetPreviewFrameAsSoftwareBitmapAsync()
    {
        // Get information about the preview
        var previewProperties = _mediaCapture.VideoDeviceController.GetMediaStreamProperties(MediaStreamType.VideoPreview) as VideoEncodingProperties;

        // Create the video frame to request a SoftwareBitmap preview frame
        var videoFrame = new VideoFrame(BitmapPixelFormat.Bgra8, (int)previewProperties.Width, (int)previewProperties.Height);

        // Capture the preview frame
        using (var currentFrame = await _mediaCapture.GetPreviewFrameAsync(videoFrame))
        {
            // Collect the resulting frame
            SoftwareBitmap previewFrame = currentFrame.SoftwareBitmap;

            // Show the frame information
            FrameInfoTextBlock.Text = String.Format("{0}x{1} {2}", previewFrame.PixelWidth, previewFrame.PixelHeight, previewFrame.BitmapPixelFormat);


            // Create a SoftwareBitmapSource to display the SoftwareBitmap to the user
            var sbSource = new SoftwareBitmapSource();
            await sbSource.SetBitmapAsync(previewFrame);

            // Display it in the Image control
            PreviewFrameImage.Source = sbSource;

        }
    }

1 个答案:

答案 0 :(得分:0)

至少有两种方式:

1)"更好"之一:

  • 创建使用SmtpClient

  • 发送电子邮件的后端
  • 使用HttpClient

  • 将您的图片从UWP发布到后端

2)"更容易"一:启动Mail app

缺点是用户将能够编辑消息,接收器和类似的东西。

你也可以尝试直接从UWP客户端使用SmtpClient(可能现在使用.Net Standard 2.0,但我想还没有人尝试过)或third-party open-source replacement(这可能有点过时了)是为Windows 8创建的,甚至尝试在客户端计算机上将后端作为Windows服务启动。

相关问题