- Home /
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 :)
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.
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.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                