I'm attempting to create a metro app that will capture an image from the tablet camera. However at time of capture I want to overlay a date stamp on the image.
/// <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);
}
}
Normally to add text on an image I'd use.
Graphics g = Graphics.FromImage
However it seems that System.Drawing is gone. What else can I use to overlay text on the captured image?
Windows.UI.Xaml doesn't have a direct raster graphics api. You can get the raw pixels from a WriteableBitmap or from a BitmapDecoder, but there is no high level way in-box to draw on them.
There are several options to draw text onto the image:
I'd start with Win2d to see if it can do what you need.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.