-
- Olivier Constance
- Posts: 9
- Joined:
Generate Images at runtime
Hello,
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 !
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
- Posts: 9
- Joined:
Re: Generate Images at runtime
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);
texture.LoadImage(bytes);
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;
obj.transform.SetParent(transform);
var img = new Noesis.Image();
img.Source = textureSrc; // Exception
If someone has idea
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);
texture.LoadImage(bytes);
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;
obj.transform.SetParent(transform);
var img = new Noesis.Image();
img.Source = textureSrc; // Exception
If someone has idea

Re: Generate Images at runtime
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
3. And last, you must assign the texture source to the image found in the XAML.
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
Code: Select all
TextureSource source = new TextureSource(texture);
Code: Select all
Image image = grid.FindName<Image>("image");
image.SetSource(source);
Who is online
Users browsing this forum: Bing [Bot] and 1 guest