Hey all!
I’m trying to load a texture from Unity’s Resources folder and use it to create a XAML Image control. I’m doing this by loading the raw bytes from the Unity texture and sending the bytes in a method like this :
private async void CreateXAMLImage(byte[] bytes, int width, int height, Canvas canvas)
{
WriteableBitmap bitmap = new WriteableBitmap(width, height);
Stream stream = bitmap.PixelBuffer.AsStream();
await stream.WriteAsync(bytes, 0, bytes.Length);
Image image = new Image();
image.Source = bitmap;
canvas.Children.Add(image);
}
Here, Canvas is the XAML Canvas, not Unity Canvas.
My issue is that this code generates oddities in the rendered texture. For example, this texture for a red button (white is transparent) :
appears like this in XAML :
In the actual texture I’m using in my project I have 3 single pixel wide lines that rise up from the top of the button, instead of having a red semi-transparent background.
Anyone has an idea on what can be causing this? Is there a better way to add dynamically some images in XAML?