Olivier Constance
Topic Author
Posts: 9
Joined: 02 Jun 2015, 15:22

Generate Images at runtime

19 May 2016, 18:56


I'm having some troubles to use generated Images.

I need to display pictures taken from device camera (stored in persistantDataPath).
I saw Images Tutorial but I cannot understand where the generated images are loaded (sorry I'm quite new/noob with Unity).

At this point I have an URI and I would like to have a similar behaviour than WPF BitmapImage.

Thank's for help !
Olivier Constance
Topic Author
Posts: 9
Joined: 02 Jun 2015, 15:22

Re: Generate Images at runtime

20 May 2016, 11:06

I think I'm on a good way to achieve that.
I create a new texture2D, create a new game object with this texture and affect Image source with texture source.

Anyway I'm getting System.InvalidOperationException: Native type is not registered when I try to set the Image source.

// Read File
var bytes = System.IO.File.ReadAllBytes(path);
var texture = new Texture2D(2, 2);
textureSrc = new Noesis.TextureSource(texture);

// Create Game Object
var sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0,0));
var obj = new GameObject();
var img = obj.AddComponent<Image>();
img.sprite = sprite;

var img = new Noesis.Image();
img.Source = textureSrc; // Exception

If someone has idea :)
User avatar
Site Admin
Posts: 3992
Joined: 20 Jan 2012, 17:18

Re: Generate Images at runtime

20 May 2016, 14:48

Hi Oliver,

The steps you must follow are:

1. First, you must get a Texture2D from Unity. It seems you have this solved.
2. Second, you must create a Noesis.TextureSource using that texture
TextureSource source = new TextureSource(texture);
3. And last, you must assign the texture source to the image found in the XAML.
Image image = grid.FindName<Image>("image");

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 6 guests