Creating an Image from an UIElement
is covered in another question.
I am however trying to make an image of an UIElement
that has the non-filled background kept as transparent. This is currently done in my code like this (NOT working for transparency):
var imageBrush_Final = new ImageBrush
{
ImageSource = bi,
Stretch = Stretch.None
};
FinalCanvas.Background.Opacity = 0;
FindChildShieldCanvas_FinalCanvas(FinalCanvas, imageBrush_Final);
FinalCanvas.InvalidateArrange();
FinalCanvas.UpdateLayout();
WriteableBitmap writeableBitmap_Finals = new WriteableBitmap(FinalCanvas, null);
String tempPNG = results.Username + "My_Crest.png";
using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream imageStream = new IsolatedStorageFileStream(tempPNG, System.IO.FileMode.OpenOrCreate, isf))
{
await Cimbalino.Toolkit.Extensions.WriteableBitmapExtensions.SavePngAsync(writeableBitmap_Finals, imageStream);
}
}
The image is created is of a canvas
that has one shape added inside. The shape is filled with an ImageBrush
, specifically imageBrush_Final
. The canvas is only partially filled by the internal shape painter that has been painted with imageBrush_Final
. I would therefore like that the created writeableBitmap_Finals
, is only filled with the shape and the rest is fully transparent.
Does anyone know how I can achieve this, and why is it not saved when the UIElement
, i.e. canvas
has set its background to Opacity
to 0
?