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
1
Question by raj231 · Jan 29, 2015 at 07:18 AM · androidcamerascreenshotgallerycapturescreenshot

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;
                     }
                 }
Comment
Add comment · Show 14
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 zharik86 · Jan 29, 2015 at 07:39 AM 0
Share

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

avatar image raj231 · Jan 29, 2015 at 07:42 AM 0
Share

yes..I've choosen External Sd Card

avatar image raj231 · Jan 29, 2015 at 07:45 AM 0
Share

yes...the CaptureScreenshot() saving to mnt/sdcard/android/data/"x.x.x"/files/name.png...But i want to save specific folder

avatar image zharik86 · Jan 29, 2015 at 08:06 AM 0
Share

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.

avatar image raj231 · Jan 29, 2015 at 08:21 AM 0
Share

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

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
-1

Answer by DeveshPandey · Sep 19, 2015 at 01:43 PM

http://u3d.as/8t8 you can use this plugin.....

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 farukcan · May 23, 2018 at 08:07 PM 0
Share

that is not reply stfu please

avatar image
0

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");
         }
 

Comment
Add comment · Show 2 · 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 aurodo · Dec 15, 2016 at 10:02 AM 0
Share

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.

avatar image sanketprabhu · Dec 16, 2016 at 06:21 AM 0
Share

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

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

25 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

Related Questions

How to save a screenshot to the camera roll (picture gallery)? 3 Answers

Open screenshot in file location Android 0 Answers

capture a screen shot and show in the album folder 1 Answer

Screenshot function not working properly ,it records button on UI ? 0 Answers

Saving Path for Screenshot 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