Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 moghes · Feb 19, 2017 at 07:40 PM · androidscreenshotpersistentdatapathdatapath

Application.CaptureScreenshot() does not save any image on Android while it does on Editor!

Hello everyone,

I know this is a common question asked before and I found many solutions which none of them still got me a solution.

Besides Application.CaptureScreenshot(), I also tried a custom function defined below.

I tried all below and no results.

 Application.CaptureScreenshot (Application.persistentDataPath + "/tsever1.png");
 StartCoroutine(TakeScreenshot (Application.persistentDataPath + "/tsever2.png"));    
 StartCoroutine(TakeScreenshot (Application.dataPath + "/tsever3.png"));
 StartCoroutine(TakeScreenshot ("/DCIM/Tsever4.png"));
 StartCoroutine(TakeScreenshot ("DCIM/Tsever5.png"));
 
 StartCoroutine(TakeScreenshot (Application.dataPath + "/DCIM/tsever6.png"));
 Application.CaptureScreenshot (Application.dataPath + "/DCIM/tsever7.png");



 private IEnumerator TakeScreenshot(string screen_path)
     {
         yield return new WaitForEndOfFrame();
         
         int width = Screen.width;
         int height = Screen.height;
         // Creates a new texture of the size of your screen.
         Texture2D tex = new Texture2D(width, height, TextureFormat.RGB24, false);
         // Reads every pixel displayed on the screen.
         tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);
         tex.Apply();
         
         // Save the screenshot as a byte array.
         byte[] bytes = tex.EncodeToPNG();
         Destroy(tex);
         // Save the screenshot on disk.
         File.WriteAllBytes(screen_path, bytes);
         Debug.Log("Screenshot (" + screen_path + ") saved!");
     }

Then I found this link: http://answers.unity3d.com/questions/845836/saving-path-for-screenshot.html

  string Screen_Shot_File_Name = "tsever.png";    

 
 Application.CaptureScreenshot(Screen_Shot_File_Name);        
 
         string Origin_Path = System.IO.Path.Combine(Application.persistentDataPath, Screen_Shot_File_Name);
         // This is the path of my folder.
         string Path = "/DCIM/Screenshots/" + Screen_Shot_File_Name;
             
         if(System.IO.File.Exists(Origin_Path))
         {
             System.IO.File.Move(Origin_Path, Path);
         }

I also read posts about FAT32 limitations .. bla bla (not much familiar), check link here: http://serverfault.com/questions/11603/how-to-check-that-all-paths-files-on-a-volume-conform-to-ext3-fat32-and-hfs/11618#11618

but I do have the file naming does not have forbidden characters..

Any help please :)

Comment
Add comment · Show 3
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 moghes · Feb 19, 2017 at 10:15 PM 0
Share

I was able to show the image as a texture on an image (raw image).

 string Screen_Shot_File_Name = "tsever.png";
 
 Application.CaptureScreenshot(Screen_Shot_File_Name);    
 
 string Origin_Path = System.IO.Path.Combine(Application.persistentDataPath, Screen_Shot_File_Name);
 
     //string Path = "/sdcard/DCI$$anonymous$$/Screenshots/" + Screen_Shot_File_Name;
     //string Path = "/DCI$$anonymous$$/Screenshots/" + Screen_Shot_File_Name;
     string Path = Application.persistentDataPath + "/" + Screen_Shot_File_Name;
 
     string url = Application.persistentDataPath + "/" + Screen_Shot_File_Name;
     var bytes = File.ReadAllBytes( url );
     Texture2D texture = new Texture2D( 150 , 150 );
     texture.LoadImage( bytes );
 
     System.IO.File.WriteAllBytes (Path, texture.EncodeToPNG());    
 
     image.texture= texture ;

And the screenshot was displayed on the image, but couldn't write.

Now I know that I am able to capture a screenshot but can't save it. problem is in System.IO.File.WriteAllBytes (Path, texture.EncodeToPNG());

I tried several different paths (as commented above), still no result.

avatar image moghes · Feb 19, 2017 at 10:17 PM 0
Share

I was able to show the image as a texture on an image (raw image).

   string Screen_Shot_File_Name = "tsever.png";
     
     Application.CaptureScreenshot(Screen_Shot_File_Name);    
     
     string Origin_Path = System.IO.Path.Combine(Application.persistentDataPath, Screen_Shot_File_Name);
     
         //string Path = "/sdcard/DCI$$anonymous$$/Screenshots/" + Screen_Shot_File_Name;
         //string Path = "/DCI$$anonymous$$/Screenshots/" + Screen_Shot_File_Name;
         string Path = Application.persistentDataPath + "/" + Screen_Shot_File_Name;
     
         string url = Application.persistentDataPath + "/" + Screen_Shot_File_Name;
         var bytes = File.ReadAllBytes( url );
         Texture2D texture = new Texture2D( 150 , 150 );
         texture.LoadImage( bytes );
     
         System.IO.File.WriteAllBytes (Path, texture.EncodeToPNG());    
     
         image.texture= texture ;

And the screenshot was displayed on the image, but couldn't write.

Now I know that I am able to capture a screenshot but can't save it. problem is in System.IO.File.WriteAllBytes (Path, texture.EncodeToPNG());

I tried several different paths (as commented above), still no result.

avatar image shuaibimran · Jun 02, 2018 at 09:08 PM 0
Share

do you get any success????

0 Replies

· Add your reply
  • Sort: 

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

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

Related Questions

[Android - Data save issues] Does the 'install location' determine the location of persistentDataPath? 1 Answer

Screenshot is not save properly into the folder. 0 Answers

Opening data file from asset folder 2 Answers

SqliteException: Unable to open the database file - Ready-made DB Provided To Access 0 Answers

Accessing custom resources on Android 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