Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Toxic Blob · Jan 04, 2011 at 04:56 AM · texture2dguitexturereadpixels

ReadPixels requires an offset while in the Editor?

I'm trying to capture the screen to a Texture2D so I can draw some custom pixels over the image and then display the frozen image back to the player as a GUITexture. When testing my capture code it seems the captureRegion requires an offset equal that to the offset of the game screen in the Unity Editor, rather than simply Rect(0,0,Screen.width,Screen.height). So if I set the Game view to "iPad Tall (768x1024)", because of my monitor layout there is a buffer of pixels around the image - and that buffer is being captured. Repeated captures will cause the image to shift up and to the right with the dark grey game view boundary repeating. Oddly, sometimes my Inspector even gets captured as a partially transparent image and overlaid on the GUITexture.

Am I doing something wrong?? What do I do instead? Thanks!

var captureRegion:Rect = Rect(0,0,Screen.width,Screen.height); function CaptureScreen() { if(captureScreen) { captureScreen = false; guiTxtr.enabled = false;

     txtr = new Texture2D(Screen.width, Screen.height);
     txtr.filterMode = FilterMode.Point;     
     txtr.ReadPixels(captureRegion, 0, 0);
     txtr.Apply();

     guiTxtr.enabled = true;
     guiTxtr.texture = txtr;
     }
 }

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image yoyo · Jan 04, 2011 at 06:51 AM 0
Share

Can you include the code that defines captureRegion?

avatar image yoyo · Jan 04, 2011 at 06:56 AM 0
Share

Note that the docs (http://unity3d.com/support/documentation/ScriptReference/Texture2D.ReadPixels.html) indicate (0,0) is the lower left of the capture region, not sure if that's relevant here. (Probably not, assu$$anonymous$$g you're consistent about use of (0,0).) Are there any other properties of Texture2D that need to be set before you can read into it? You might try passing false for recalculate$$anonymous$$ipmaps and see if that helps.

avatar image Toxic Blob · Jan 04, 2011 at 10:52 PM 0
Share

Ahh, I had an answer from @aras_p via twitter that said this is apparently a bug that will be fixed for the next version of Unity.

avatar image Demigiant · Nov 28, 2015 at 05:31 PM 2
Share

It's the end of 2015 and this still isn't fixed :(

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by PaulUsul · Jan 04, 2011 at 10:33 AM

I have also had this problem, it seems that it take the entire game window tab rather than the actual window. I just resize my window to the fixed resolution or just set it to free aspect. This is probably a bug report worthy thou..

[Side note] When taking screenshots I would recommend using the full Texture2D constructor as right now you have mipmaps on and have a alpha channal.

txtr = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Toxic Blob · Jan 04, 2011 at 10:53 PM 0
Share

Thanks for the tip on the full Texture2D constructor

avatar image
1

Answer by PaulUsul · Jan 04, 2011 at 12:17 PM

It could also be because you are not waiting for the end of the frame, so the camera is not actually rendered.

pop this in before captureScreen = false;

// We should only read the screen buffer after rendering is complete
yield WaitForEndOfFrame();

you can read more here http://unity3d.com/support/documentation/ScriptReference/Texture2D.EncodeToPNG.html

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

Wait for Texture.ReadPixels 1 Answer

Why are my GUI textures distorted? 1 Answer

Issue With Simultaneous ReadPixels Calls 0 Answers

Unassigned Reference Exception. How to create and add a texture 2D in the inspector? 0 Answers

Using Screenshot as Texture 4 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges