Author Topic: Creating PNG from GUI object  (Read 6330 times)

Tripwire

  • Full Member
  • ***
  • Thank You
  • -Given: 9
  • -Receive: 0
  • Posts: 163
    • View Profile
Creating PNG from GUI object
« on: April 30, 2014, 03:12:36 AM »
Hi,

I'm trying to create a PNG of a part of the NGUI UI which is customizable by the user. The object i'm trying to create a PNG of consists of the following objects:
UITexture
 -Sprite
 -Sprite
 -label

I've tried using readpixels but I can't get the position right. I also tried using a render texture but that only gives me a black texture in the end. Is NGUI providing something like this to create a PNG from UI object? If not how would I achieve this?



r.pedra

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 20
  • Posts: 131
    • View Profile
Re: Creating PNG from GUI object
« Reply #1 on: April 30, 2014, 03:52:30 AM »
You can do it by moving the things you want to capture into another UI. Then you can use a RenderTexture on the Camera and capture the pixels.

Tripwire

  • Full Member
  • ***
  • Thank You
  • -Given: 9
  • -Receive: 0
  • Posts: 163
    • View Profile
Re: Creating PNG from GUI object
« Reply #2 on: April 30, 2014, 04:33:52 AM »
thx for the reply! Can you give an example? I have no idea how to do this actually.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Creating PNG from GUI object
« Reply #3 on: April 30, 2014, 05:16:54 PM »
Just the ordinary way render textures work in Unity. Set up a camera, create a render texture, assign the camera to render into this render texture. Everything drawn by this camera will be in the render texture that you can then draw using a UITexture. Check Unity's docs on how to create and use render textures.