I have written a code in Windows 8.1 app to crop a picture and save it using the tutorial
http://code.msdn.microsoft.com/windowsapps/CSWin8AppCropBitmap-52fa1ad7
Now i want to edit the picture adding shapes like Ellipse on the picture. For that i created an ellipse
var Circle = new Ellipse
{
Height = 50,
Width = 50,
Fill = brush,
RenderTransform = new CompositeTransform(),
};
and add it in canvas which contain my above picture loaded from computer as:
imageCanvas.Children.Add(Circle);
I can see the ellipse loaded in my original pic but when saving, only my original picture is saved(not with ellipse).I want to edit picture embedding the ellipse into my original picture. How can i do it?
I think you are saving the image and thats why only the image is saved and not the circle on the image. To save the editted image with circle, you NEED TO SAVE THE CHILDREN OF CANVAS
Assuming you are well acquainted with IRandomAccesStream and Encoder classes, I am giving here my code which i used sometimes back which works 100%. In the code, I have also given the facility of FileSavePicker through which user saves the picture in its desired location. Here, can is the name of canvas
private async void save_Click(object sender, RoutedEventArgs e)
{
if (can != null)
{
RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap();
await renderTargetBitmap.RenderAsync(can);
FileSavePicker picker = new FileSavePicker();
picker.FileTypeChoices.Add("PNG Image",new string[]{".png"});
StorageFile file = await picker.PickSaveFileAsync();
if (file != null)
{
var pixels = await renderTargetBitmap.GetPixelsAsync();
using (IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.ReadWrite))
{
var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, stream);
byte[] bytes = pixels.ToArray();
encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore, (uint)can.Width, (uint)can.Height, 96, 96, bytes);
await encoder.FlushAsync();
}
}
}
}