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
0
Question by w4der · Aug 20, 2012 at 11:55 AM · androidiosscreenshot

Screenshot on iOS and Android not working

Hi there, I have problem with taking screenshot on iOS and Android. Using Unity 3D editor all working fine. On Android it make something like that: alt text

On iOS it shows me pictures with question marks. Please help me. Can someone do this for me? P.S. Sorry for my english ;) Code that causes this issue is below. I'm using Win 7 64 bit and Unity 3D 3.5.5f

 using UnityEngine;
 using System.Collections;
 using System.IO;
 
 public class PaintScreenshot : MonoBehaviour 
 {    
     public string fileName;             // Name of the screenshot - without '.png'
     public string fileNameThumb;        // Name of the thumbnail screenshot - without '.png'
     
     string path;
     WWW tex;
     
     public static PaintScreenshot instance
     {
         get{
             if( m_Instance == null )
             {
                 GameObject go = new GameObject("Screenshot Manager");
                 m_Instance = go.AddComponent<PaintScreenshot>() as PaintScreenshot;
             }
             return m_Instance;
         }
     }
     private static PaintScreenshot m_Instance;
         
     
     public void TakeScreenshotStart()
     {
         StartCoroutine( TakeScreenshot() );
 
         
     }
     
     IEnumerator TakeScreenshot()
     {        
         //    yield return StartCoroutine( UploadPNG(0.05f) );                            // Start Old Version of TakeScreenshot and comment lines below this line
             yield return StartCoroutine( TakeScreenshot(0.05f) );
             
             fileName = System.DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss-ff");            // File name based on date and time
             fileNameThumb = fileName + "-thumb";
             fileName += ".png";
             fileNameThumb += ".png";
             
             path = Application.persistentDataPath;
             Application.CaptureScreenshot(path + "/" + fileName);
             
             
             // Save thumb
             // More help at: http://answers.unity3d.com/questions/18647/unity-iphone-can-i-store-data-on-the-iphone-to-be.html
             Texture2D tex = new Texture2D( 150, 150, TextureFormat.RGB24, false );
         
                // Read screen contents into the texture
             tex.ReadPixels( new Rect((Screen.width - 150) / 2, (Screen.height - 150) / 2, 150, 150), 0, 0 );    // Thumb Screenshot only from center of the screen
             tex.Apply();
     
                // Encode texture into PNG
             byte[] bytes = tex.EncodeToPNG();
             FileStream fs = new FileStream(path + "/" + fileNameThumb, FileMode.Create);
             BinaryWriter w = new BinaryWriter(fs);
             w.Write(bytes);
             w.Close();
             fs.Close();
                 
             Debug.Log("Screenshot at: " + path + "/" + fileName);
             
             
             yield return new WaitForSeconds(0.05f);                
             print("Screenshot is ready");
             
     }
     
     IEnumerator TakeScreenshot( float seconds )
     {
         yield return new WaitForSeconds(seconds);
     }
     
     byte[] GetBytes()
     {    
         // Create a texture the size of the screen, RGB24 format
         int width = Screen.width;
         int height = Screen.height;
         Texture2D tex = new Texture2D( width, height, TextureFormat.RGB24, false );
         
         // Read screen contents into the texture
         tex.ReadPixels( new Rect(0, 0, width, height), 0, 0 );
         tex.Apply();
     
         // Encode texture into PNG
         byte[] bytes = tex.EncodeToPNG();
         Destroy( tex );
         
         return bytes;
     }
     
     byte[] GetBytesThumb()
     {    
         // Create a texture only from part of the screen, RGB24 format
 //        int width = thumbWidth;
      //   int height = thumbHeight;
         Texture2D tex = new Texture2D( 150, 150, TextureFormat.RGB24, false );
         
         // Read screen contents into the texture
         tex.ReadPixels( new Rect((Screen.width - 150) / 2, (Screen.height - 150) / 2, 150, 150), 0, 0 );    // Thumb Screenshot only from center of the screen
         tex.Apply();
     
         // Encode texture into PNG
         byte[] bytes = tex.EncodeToPNG();
         Destroy( tex );
         
         return bytes;
     }
         
     IEnumerator UploadPNG( float seconds )
     {
         yield return new WaitForSeconds(seconds);
         
         // We should only read the screen after all rendering is complete
         yield return new WaitForEndOfFrame();
         byte[] bytes = GetBytes();
                 
         fileName = System.DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss-ff");            // File name based on date and time
         fileNameThumb = fileName + "-thumb";
         
         Debug.Log("Normal: " + Application.persistentDataPath + "/" + fileName + ".png");
         Debug.Log("Thumb: " + Application.persistentDataPath + "/" + fileNameThumb + ".png");
         
         FileStream fs = new FileStream(Application.persistentDataPath + "/" + fileName + ".png", FileMode.Create);
         BinaryWriter w = new BinaryWriter(fs);
         w.Write(bytes);
         w.Close();
         fs.Close();
         
         byte[] bytesThumb = GetBytesThumb();
         FileStream fsThumb = new FileStream(Application.persistentDataPath + "/" + fileNameThumb + ".png", FileMode.Create);
         BinaryWriter wThumb = new BinaryWriter(fsThumb);
         wThumb.Write(bytesThumb);
         wThumb.Close();
         fsThumb.Close();
         
         
         
         yield return new WaitForSeconds(seconds);
         print("screenshot is ready");
     }
     
 
 }
 
 


thumbs.jpg (120.6 kB)
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Paulius-Liekis · Aug 20, 2012 at 12:08 PM

Try adding coroutine WaitForEndOfFrame call before Application.CaptureScreenshot.

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

8 People are following this question.

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

Related Questions

Save Screenshot and Show it in Gallery (iOS & Android) 3 Answers

Share Screenshot Image to Facebook with Facebook SDK 0 Answers

How to play sound during screenshot, even when device muted 1 Answer

Facebook app review for screenshot share 0 Answers

[NGUI] Sprites breaking on switching from Android 0 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