I'm using the Blit method for image annotation functionality in a Windows Store app. Essentially the user takes a picture and is able to use the Windows.UI.Input.Inking.InkManager to draw on the picture (e.g. circles, boxes, etc). I'm then using the Blit method to combine the picture the user took with the annotation produced by the InkManager. The problem is that the combined saved image has the mark up from the InkManager appearing horizontally offset.
See https://onedrive.live.com/?cid=c21327df8f57089d#cid=C21327DF8F57089D&id=C21327DF8F57089D%21157 for examples of the original and saved (blitted) image.
The code to save the blitted images:
See https://onedrive.live.com/?cid=c21327df8f57089d#cid=C21327DF8F57089D&id=C21327DF8F57089D%21157 for examples of the original and saved (blitted) image.
The code to save the blitted images:
private async Task SaveMergedImages()
{
//Image foreground
Windows.UI.Xaml.Media.Imaging.WriteableBitmap foregroundBmp;
using (var a = new InMemoryRandomAccessStream())
{
//CurrentManager is a Windows.UI.Input.Inking.InkManager
await CurrentManager.SaveAsync(a);
a.Seek(0);
foregroundBmp = await new Windows.UI.Xaml.Media.Imaging.WriteableBitmap(Convert.ToInt32(CurrentManager.BoundingRect.Width), Convert.ToInt32(CurrentManager.BoundingRect.Height)).FromStream(a);
}
Windows.UI.Xaml.Media.Imaging.WriteableBitmap backgroundBmp = null;
using (var ims = new InMemoryRandomAccessStream())
{
using (var dataWriter = new DataWriter(ims))
{
//ViewModel.ImageByteArrayToBeEdited is a byte[] of the image thats going to be edited
dataWriter.WriteBytes(ViewModel.ImageByteArrayToBeEdited);
await dataWriter.StoreAsync();
backgroundBmp = new Windows.UI.Xaml.Media.Imaging.WriteableBitmap(ViewModel.ImageToBeEdited.PixelWidth, ViewModel.ImageToBeEdited.PixelHeight);
ims.Seek(0);
//set the source of the in memory bmp as blit relies upon the SourceURI
await backgroundBmp.SetSourceAsync(ims);
}
}
//merge 'em!
backgroundBmp.Blit(
new Rect(CurrentManager.BoundingRect.X, CurrentManager.BoundingRect.Y, foregroundBmp.PixelWidth, foregroundBmp.PixelHeight),
foregroundBmp,
new Rect(0, 0, foregroundBmp.PixelWidth, foregroundBmp.PixelHeight),
WriteableBitmapExtensions.BlendMode.Alpha);
await backgroundBmp.SaveToFile();
}
This is all being done on a XAML page that has a Canvas with the canvas Background set to an ImageBrush.//Windows.UI.Xaml.Controls.Canvas
InkCanvas.Background = new ImageBrush()
{
ImageSource = ViewModel.ImageToBeEdited,
Stretch = Stretch.Uniform
};
I've tried various tweaks to the code, including changing the Stretch of the ImageBrush and multiple variations Rect params of the Blit method. None have worked. Please help.