Genom
Topic Author
Posts: 47
Joined: 04 Dec 2014, 14:47

Getting an image from a Texture2D

17 Oct 2015, 17:19

Hy guys, while I'm trying to do this:
        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");
        }
the code that is calling this method is
            var imageBytes = File.ReadAllBytes(imagePath);
            ViewModelFactory.GetViewModel<OrderPicturesViewModel>().AddImage(imageBytes, AUP.Utils.LoadTexture(imagePath));
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!
 
Genom
Topic Author
Posts: 47
Joined: 04 Dec 2014, 14:47

Re: Getting an image from a Texture2D

17 Oct 2015, 22:06

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.
 
User avatar
ai_enabled
Posts: 221
Joined: 18 Jul 2013, 05:28
Contact:

Re: Getting an image from a Texture2D

20 Oct 2015, 12:09

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.
AtomicTorch Studio Pte. Ltd. http://atomictorch.com

Who is online

Users browsing this forum: noizex and 0 guests