[英]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.