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
3
Question by nogue2k · Jul 04, 2012 at 03:24 PM · texturetexture2dscreenshotreadpixelssnapshot

Using Screenshot as Texture

I want to take a screenshot and use it as a material texture for another object.

Script so far:

 public IEnumerator TakeSnapshot(int width, int height)
 {
     yield return new WaitForSeconds(5);

     Texture2D texture = new Texture2D (width, height, TextureFormat.RGB24, true);

     texture.ReadPixels(new Rect(0, 0, width, height), 0, 0);
 

snapshot = texture; }

then im using

 fotoPlane.renderer.material.mainTexture = snapshot;

but this is just creating a gray texture instead of getting the screen image.

Comment
Add comment
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

4 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by nogue2k · Jul 04, 2012 at 03:28 PM

i forgot the texture.Apply(); after texture.ReadPixels. That solved it. I will leave the question here in case someone has the same problem.

StartCoroutine(TakeSnapshot(Screen.width,Screen.height));

public IEnumerator TakeSnapshot(int width, int height) { yield return new WaitForSeconds(0.1F); Texture2D texture = new Texture2D (width, height, TextureFormat.RGB24, true); texture.ReadPixels(new Rect(0, 0, width, height), 0, 0); texture.Apply(); snapshot = texture; }

and then


    gameObject.renderer.material.mainTexture = snapshot;

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 BobbyDoogle · Mar 19, 2014 at 07:39 PM 0
Share

Hey this worked great for me, but I am getting an error ReadPixels was called to read pixels from system frame buffer, while not inside drawing frame. Any way to fix this?

avatar image
3
Wiki

Answer by moonchacha · Mar 07, 2014 at 08:39 PM

Nice. It looks like using "yield return new WaitForEndOfFrame();" might be a little cleaner.

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
avatar image
0

Answer by Lexxxx · Feb 04, 2016 at 09:40 AM

Very useful information! Thanks a lot!=)

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
avatar image
0

Answer by Raclette · Jun 03, 2017 at 11:33 AM

Thank you it’s very useful for me. I was wondering if it’s possible to snapshot a specific region of the screen? I try to make a little drawing game and I want to save only the region of the paper. Any idea how can I do that? Thank you

alt text


dessin.jpg (68.2 kB)
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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Texture.Apply() Crashes at Resolutions under 1920x1080 1 Answer

Texture2D readPixels: How to only read a section of the camera view? 0 Answers

Trying to read pixel out of bounds - screenshot of just half the screen 1 Answer

Application.CaptureScreenshot on a Texture2D? 1 Answer

What's wrong with my screenshot function? 1 Answer


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