Getting an image from a Texture2D
Hy guys, while I'm trying to do this:
the code that is calling this method is
I get a "can't create TextureSource texture native pointer is null" error, any idea why?
Also, I'd like to know how to create a ImageSource directlyfrom a byte array, do you know how can I do this with Noesis.Image?
thank you!
Code: Select all
public void AddImage(byte[] imgBytes, Texture2D rawImage)
{
var ts = new TextureSource(rawImage);
var img = new Image { Source = ts };
AvailableItems.Add(new CustomItem() { ThumbnailImage = img });
NotifyPropertyChanged("AvailableItems");
}
Code: Select all
var imageBytes = File.ReadAllBytes(imagePath);
ViewModelFactory.GetViewModel<OrderPicturesViewModel>().AddImage(imageBytes, AUP.Utils.LoadTexture(imagePath));
Also, I'd like to know how to create a ImageSource directlyfrom a byte array, do you know how can I do this with Noesis.Image?
thank you!
Re: Getting an image from a Texture2D
Ok, I know what's happening, this can be done only in the main thread. In a secondary one the pointer is not being generated by Unity3D. I'll figure out how to do it in the main one.
-
- ai_enabled
- Posts: 221
- Joined:
- Contact:
Re: Getting an image from a Texture2D
Yes, you need to work with Unity API only from the main thread.
To do so you could use any multithreading-helper library available (for example, LOOM https://www.assetstore.unity3d.com/en/#!/content/7285 or Thread Ninja https://www.assetstore.unity3d.com/en/#!/content/15717 (free)) or write your own - it's quite simple if you know the threading primitives.
To do so you could use any multithreading-helper library available (for example, LOOM https://www.assetstore.unity3d.com/en/#!/content/7285 or Thread Ninja https://www.assetstore.unity3d.com/en/#!/content/15717 (free)) or write your own - it's quite simple if you know the threading primitives.
AtomicTorch Studio Pte. Ltd. http://atomictorch.com
Who is online
Users browsing this forum: No registered users and 0 guests