C# 将文本添加到来自摄影机捕获的图像中

C# 将文本添加到来自摄影机捕获的图像中,c#,windows-store-apps,windows-8.1,C#,Windows Store Apps,Windows 8.1,我正在尝试创建一个metro应用程序,它将从平板电脑摄像头捕获图像。 然而,在拍摄时,我想在图像上覆盖一个日期戳 /// <summary> /// This is the click handler for the 'CaptureButton' button. /// </summary> /// <param name="sender"></param> /// <param name="e">&l

我正在尝试创建一个metro应用程序,它将从平板电脑摄像头捕获图像。 然而,在拍摄时,我想在图像上覆盖一个日期戳

/// <summary>
    /// This is the click handler for the 'CaptureButton' button.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private async void CapturePhoto_Click(object sender, RoutedEventArgs e)
    {
        try
        {
            rootPage.NotifyUser("", NotifyType.StatusMessage);

            // Using Windows.Media.Capture.CameraCaptureUI API to capture a photo
            CameraCaptureUI dialog = new CameraCaptureUI();
            Size aspectRatio = new Size(16, 9);
            dialog.PhotoSettings.CroppedAspectRatio = aspectRatio;

            StorageFile file = await dialog.CaptureFileAsync(CameraCaptureUIMode.Photo);
            if (file != null)
            {
                BitmapImage bitmapImage = new BitmapImage();
                using (IRandomAccessStream fileStream = await file.OpenAsync(FileAccessMode.Read))
                {
                    bitmapImage.SetSource(fileStream);
                }

                // add code for text overlay here


                CapturedPhoto.Source = bitmapImage;
                ResetButton.Visibility = Visibility.Visible;

                // Store the file path in Application Data
                appSettings[photoKey] = file.Path;
            }
            else
            {
                rootPage.NotifyUser("No photo captured.", NotifyType.StatusMessage);
            }
        }
        catch (Exception ex)
        {
            rootPage.NotifyUser(ex.Message, NotifyType.ErrorMessage);
        }
    }

然而,似乎这个系统。绘图已经不存在了。我还可以使用什么在捕获的图像上覆盖文本?

Windows.UI.Xaml没有直接光栅图形api。您可以从WriteableBitmap或BitmapDecoder获取原始像素,但并没有高级方法在方框中绘制它们

有几个选项可以在图像上绘制文本:

  • 互操作到DirectWrite并传入位图进行操作
  • 找到一个第三方库,它将直接在您的像素上绘制 缓冲区(我不确定是否有人能做到这一点:对于一般图纸,有很多 人们使用WriteableBitmapEx,但我不相信它可以在 Windows运行时应用程序。另请查看WinRTXamlToolkit)
  • 在图像控件和文本块中使用位图创建网格 使用覆盖,然后使用RenderTargetBitmap将网格渲染到 位图
  • Win2d旨在向Windows应用商店公开Direct2d 应用程序。这是一项正在进行的工作,但文本目前正在执行。 看
  • 我会从Win2d开始,看看它是否能满足您的需要

    Graphics g = Graphics.FromImage