[英]Add text to image from camera capture
我正在尝试创建一个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);
}
}
通常,在要使用的图像上添加文本。
Graphics g = Graphics.FromImage
但是,似乎System.Drawing已经消失了。 我还能使用什么在捕获的图像上覆盖文本?
Windows.UI.Xaml没有直接的栅格图形API。 您可以从WriteableBitmap或BitmapDecoder获取原始像素,但是没有高级的内置方法可以在其上进行绘制。
有几种选项可将文本绘制到图像上:
我将从Win2d开始,看看它是否可以满足您的需求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.