- Home /
Screenshot is not saving to Gallery and folder
I'm taking screenshot using Application.Capturescreenshot code and it's taking the screenshot then storing to default location. But i want to store this screenshot into one specific folder and it should display in the gallery folder also. I used below code but the screenshot is not saving to SDCard and gallery.
 if (GUI.Button(new Rect(Screen.width-85,Screen.height-(Screen.height-80),80,80), Zoom_Tex,camera_icon_style)) {
                 
                     Screen_Shot_File_Name = model.name + System.DateTime.Now.ToString("__yyyy-MM-dd") + ".png";
                     Application.CaptureScreenshot(Screen_Shot_File_Name);
                     Shot_Taken = true;
                     //Debug.Log("path save is "+Screen_Shot_File_Name);
                     
 
                 }
                 if(Shot_Taken == true)
                 {
                     string Origin_Path = System.IO.Path.Combine(Application.persistentDataPath, Screen_Shot_File_Name);
                     Debug.Log("Origin_Path save is "+Origin_Path);
 
                     // This is the path of my folder.
                 
                     string Path = "/mnt/sdcard/DCIM/Inde/" + Screen_Shot_File_Name;
                     Debug.Log("Path save is "+Path);
                     if(System.IO.File.Exists(Origin_Path))
                     {
                         System.IO.File.Move(Origin_Path, Path);
                         Debug.Log("Path_move save is "+Path);
                         Shot_Taken = false;
                     }
                 }
Are you have a check this options Edit->Project Settings->Player->OtherSettings->WriteAccess->External Sd Card?
And, if I'm not mistakes, CaptureScreenshot() save file into mnt/sdcard/android/data/"x.x.x"/files/name.png
yes...the CaptureScreenshot() saving to mnt/sdcard/android/data/"x.x.x"/files/name.png...But i want to save specific folder
Try create and save screenshot another way:
  if(GUI.Button(new Rect(Screen.width-85,Screen.height-(Screen.height-80),80,80), Zoom_Tex,camera_icon_style)) {
   Screen_Shot_File_Name = model.name + System.DateTime.Now.ToString("__yyyy-$$anonymous$$$$anonymous$$-dd") + ".png";
   Texture2D tex = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
   tex.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
   tex.Apply();
   byte[] bytes = tex.EncodeToPNG();
   string filename = "/sdcard/DCI$$anonymous$$/Inde/" + Screen_Shot_File_Name;
   //Write bytes
   System.IO.File.WriteAllBytes(filename, bytes);
   Destroy(tex); //Destroy texture from memory
   //Or use binary writer
   //System.IO.File file = new System.IO.File.Open(filename, System.IO.File$$anonymous$$ode.Create);
   //System.IO.BinaryWriter binary= new System.IO.BinaryWriter(file);
   //binary.Write(bytes);
   //file.Close();
  }
But remember, directory to write must be created.
I've tried your code but it's not working ever the screenshot is not saving to this path also mnt/sdcard/android/data/"x.x.x"/files/name.png
Answer by sanketprabhu · Aug 04, 2016 at 04:10 PM
 void captureScreenshot(string result){
         if (result == "true") {
             StartCoroutine(CaptureScreen());
         } 
     }
 
     void OnGUI(){
         if (GUI.Button (new Rect (20, 70, 100, 45), "Click"))
             captureScreenshot ("true");
             
         
     }
     public IEnumerator CaptureScreen()
     {
         // Wait for screen rendering to complete
         yield return new WaitForEndOfFrame();
         Application.CaptureScreenshot ("screenshot.png");
 
             string Origin_Path = System.IO.Path.Combine (Application.persistentDataPath, "screenshot.png");
             Debug.Log ("Origin_Path save is " + Origin_Path);
 
             // This is the path of my folder.
             string Path = "/mnt/sdcard/" + "screenshot.png";
             Debug.Log ("Path save is " + Path);
             if (System.IO.File.Exists (Origin_Path)) {
                 System.IO.File.Move (Origin_Path, Path);
                 Debug.Log ("Path_move save is " + Path);
             }
         jo.Call<bool> ("screenshotHandler", "screenshot.png");
         }
 
Hi Sanket,
Your solution works partially. The screenshot is captured and stored at the location "Application.persistentDataPath" but "System.IO.File.Exists(Origin_Path)" returns false.
So, unable to move file to sd-card at this location: "/mnt/sdcard/" . Have I missed something? and any idea why "System.IO.File.Exists(Origin_Path)" returns false whereas the file does exist.
Please share your views on how to move/copy file to sd-card.
If Error: System.IO.File.Exists (Origin_Path) //returns FALSE even though file exists at Origin_Path.
Please try this:
 public IEnumerator CaptureScreen()
     {   
         Application.CaptureScreenshot ("../../../../DCI$$anonymous$$/"+fileName);
         Debug.Log ("Sanky: Screen Captured");
 
             while (!File.Exists (filePath)) {
                 Debug.Log ("Sanky: File exist at location"+filePath);
                 yield return 0; 
             } /////// do whatever you want }
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                