Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Tripwire on December 09, 2013, 03:57:43 PM

Title: Converting UITexture / UISprite to Texture2D
Post by: Tripwire on December 09, 2013, 03:57:43 PM
Hi,

How would I convert a UISprite / UITexture to a Texture2D?

Title: Re: Converting UITexture / UISprite to Texture2D
Post by: ArenMook on December 09, 2013, 04:20:03 PM
Select it in the atlas, Extract Sprite, save as a texture.
Title: Re: Converting UITexture / UISprite to Texture2D
Post by: Tripwire on December 12, 2013, 03:47:39 AM
Select it in the atlas, Extract Sprite, save as a texture.

Thx for your reply. But how do I extract the sprite? Selecting it and saving it is no problem :). And how do I convert a UITexture to Texture2D?
Title: Re: Converting UITexture / UISprite to Texture2D
Post by: ArenMook on December 12, 2013, 06:09:21 AM
You can extract the sprite exactly as I said in the last post. Select it in the Atlas. You will see the button. Make sure you have the latest NGUI.
Title: Re: Converting UITexture / UISprite to Texture2D
Post by: Tripwire on December 12, 2013, 08:28:49 AM
You can extract the sprite exactly as I said in the last post. Select it in the Atlas. You will see the button. Make sure you have the latest NGUI.

Hi ArenMook,

Thanks for your reply. Maybe I should have mentioned i'm using NGUI 2.7.0. Furthermore I think my question wasn't exactly clear, I meant how to convert a UITexture and UISprite to Texture2D at runtime.
Title: Re: Converting UITexture / UISprite to Texture2D
Post by: ArenMook on December 12, 2013, 11:04:18 AM
NGUI 2.7 doesn't have the feature I am talking about, and no longer has direct support due to it being deprecated. Furthermore, I don't understand what you're trying to do and why. Convert a sprite to a texture at run-time? What? Why? UITexture draws a 2D texture. Sprite draws a part of a 2D texture. What's there to convert?
Title: Re: Converting UITexture / UISprite to Texture2D
Post by: Tripwire on December 12, 2013, 03:41:56 PM
NGUI 2.7 doesn't have the feature I am talking about, and no longer has direct support due to it being deprecated. Furthermore, I don't understand what you're trying to do and why. Convert a sprite to a texture at run-time? What? Why? UITexture draws a 2D texture. Sprite draws a part of a 2D texture. What's there to convert?

Maybe i'm thinking to difficult. I have 2 sprites and a UITexture which I need merge and then save as a PNG file and set in the Android Gallery or emailed. This said, I have found a merging script which works with Texture2D's so my idea was to convert the UISprite and UITexture to Texture2D. Then merge the textures into 1 png.

I thought of maybe making a screen capture and then with a mask cutting out the rest of the screen leaving only the Texture which I need to save.

Or do you have a better solution to do this?
Title: Re: Converting UITexture / UISprite to Texture2D
Post by: ArenMook on December 13, 2013, 05:13:15 AM
Set up an off-screen camera, render to texture, save the result as a PNG. That would be my suggestion and would involve the least amount of code.

If not that, then you have to manually read pixels from specific parts of the atlas using the sprite (atlas.GetSprite("name")). As I said NGUI simply draws parts of the atlas texture, with the actual area defined from the data you get from atlas.GetSprite. You're welcome to read it manually yourself using readpixels and then do what you want with it.