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
2
Question by cfdevdan · Nov 05, 2012 at 10:28 PM · screenshotreadpixelsqcar

Texture2d.readPixels not working with iOS 6

I've made an iOS app with Unity 3.5.6 and QCAR for iPad. The app uses readPixels to take a screenshot of the AR scene and has worked great unless I try it on an iPad with iOS 6, then it only makes a black texture. I get the warning mentioned in the Unity 3.5.6 change log saying "ReadPixels was called to read pixels from system frame buffer, while not inside drawing frame." , but I get this error on an iOS 5.x device too and readpixels takes the screenshot. I'm calling readpixels in OnGUI() when a button is clicked, and use a co-routine to wait for the end of the current frame. I've tried it without the co-routine, with the co-routine between readPixels and Apply(), and tried calling readPixels in Update(), which captured only the background, no AR elements. Anyone else dealt with this?

 void OnGUI(){
         
         GUI.Box(new Rect(0, Screen.height - 125, Screen.width, 150), bottomBar, bottom);
         
         // make screen capture button
         if(GUI.Button(new Rect(309, 910, 150, 100),cameraBtn,cameraIcon)){
             audio.Play();
             CaptureImage();
             clicked = true;
             
             Application.LoadLevel("Preview");
         }
         
         // alert box
         if(clicked){
             GUI.Box(new Rect( 282, 425, 204, 80), alert, alertGS);
         } // end alert box
         
     }// end OnGUI()
 
     
     void CaptureImage(){
             
             clicked = true;
         
             // wait for end of current frame
             StartCoroutine(waitForEnd());
             
             // create texture to hold image
             tex = new Texture2D(width, height, TextureFormat.RGB24, false);
             
             // capture the image
             tex.ReadPixels(new Rect(0, 125, width, height), 0,0);
             tex.Apply();
         
             Application.LoadLevel("Preview");
             
     } // end CaptureImage     
 
     
     
     IEnumerator waitForEnd(){
         
         yield return new WaitForEndOfFrame();
         
     } // end waitForEnd
Comment
Add comment · Show 6
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 DeveshPandey · Nov 26, 2012 at 05:43 AM 0
Share

Please tell me one thing that, have you change the Application. Application.targetFrameRate for the device?

avatar image cfdevdan · Nov 26, 2012 at 01:51 PM 0
Share

@DeveshPandey: no I did not change the target frame rate.

avatar image DeveshPandey · Nov 26, 2012 at 02:29 PM 0
Share

then O$$anonymous$$, but how can this code works without saving the texture. You need to write/save the texture after tex.Apply(); and then LoadLevel("preview"). http://docs.unity3d.com/Documentation/ScriptReference/Texture2D.EncodeToPNG.html

avatar image cfdevdan · Nov 26, 2012 at 06:17 PM 0
Share

For this app I call Texture2d.EncodeToPNG in another script in another scene. It's called right before I create the request (WWW) to upload the screenshot and user info. This app uploads the screenshot to a server and does not save it because it is part of a display/attraction in a retail store and has already taken over 10k pics in 2 months.

avatar image OP_toss · Jan 31, 2014 at 06:03 PM 0
Share

Can you use Application.CaptureScreenshot() for your purposes ins$$anonymous$$d?

Show more comments

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Paulius-Liekis · Nov 06, 2012 at 09:45 AM

CaptureImage supposed to be coroutine.

You need to change `StartCoroutine(waitForEnd());` to `yield return StartCoroutine(waitForEnd());`, otherwise it doesn't wait for waitForEnd to finish and just continues on. Also you don't need waitForEnd at all, you can simply call WaitForEndOfFrame directly from CaptureImage.

Code:

 IEnumerator CaptureImage(){
      clicked = true;

      // wait for end of current frame
      yield return new WaitForEndOfFrame();

      // create texture to hold image
      tex = new Texture2D(width, height, TextureFormat.RGB24, false);

      // capture the image
      tex.ReadPixels(new Rect(0, 125, width, height), 0,0);
      tex.Apply();

      Application.LoadLevel("Preview");

 } // end CaptureImage

Also be careful when pasting Javascrip coroutine example code into C# code, that's how you end up with StartCoroutine instead of yield return StartCoroutine. Javascript does some thing behind your back (I don't like it :))

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 cfdevdan · Nov 06, 2012 at 09:20 PM 0
Share

Thanks for responding. I tried this but no luck with iOS6, works with iOS 5. It might work with a regular Unity app, but with this QCAR app it just gives me an empty texture, just blue screen where the image should be. BTW, that's not JavaScript, it's from the Unity docs. Apparently there is an iOS 6 bug with glReadPixels, looking for a way around it.

avatar image
0

Answer by cfdevdan · Nov 07, 2012 at 09:37 PM

It seems that this is an iOS 6 bug. There have been a few bug reports generated about it and it is discussed on the Apple Developer Forums. The suggested fix is to use retained backing on the EAGLView. I ended up changing the boolean in the drawableProperties of the CAEAGLLayer in AppController.mm from FALSE to TRUE. See below. Apple cautions that this fix can affect performance but I don't see any problems and several others have fixed the bug with this without issue.

 layer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
 // change FALSE to TRUE
 [NSNumber numberWithBool:TRUE], kEAGLDrawablePropertyRetainedBacking,
 colorFormat, kEAGLDrawablePropertyColorFormat, nil ];
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 ina · Jan 31, 2014 at 05:48 PM

Try QualitySettings.antiAliasing = 0

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

14 People are following this question.

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

Related Questions

Preview of screenshot in unity 2 Answers

Is there any way to execute ReadPixels (for capturing a screenshot) but on a camera that is currently not displaying anything on screen? 2 Answers

How to get banner ad's screenshot to a texture? 0 Answers

Using Texture2D.GetPixels() to take a screenshot and then show it on an Image - iOS problems. 1 Answer

ReadPixels problem 3 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