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 /
This question was closed Jul 31, 2014 at 05:34 AM by ODNSEV7N for the following reason:

Other

avatar image
0
Question by ODNSEV7N · Jul 14, 2014 at 09:25 AM · string formatting

String.Format won't work on Android.

Hi, I was just wondering what could be preventing this to work on Android Devices. It takes the screenshot on PC inside the editor, but not on mobile.

The commented out line works fine on android.

Also the folder is created in the mobile environment but the screenshots are not saved there.

Is it wrong syntax for mobile?

Thanks, Tim.

  import System.IO;
  import System.Collections;
         
         
         var folder = "";
         var frameRate = 0;
          
         function Start () {
             Time.captureFramerate = frameRate;
             System.IO.Directory.CreateDirectory(folder);
             TakeScreenShot ();
         
         }
         function Awake (){
         folder = Application.persistentDataPath + "/../../../../DCIM/TestShots/";
         
         }
          

         
         function TakeScreenShot (){
         var info3 = new DirectoryInfo(folder);
         var fileInfo3 = info3.GetFiles();
         var name = String.Format("{0}/{1:D04} shot.png", folder, Time.frameCount );
 
                 Application.CaptureScreenshot(name);
                 
     //        Application.CaptureScreenshot("Shot"+info3.GetFiles().Length +".png");
              
                 
              } 





EDIT: I have this now, it will take and save in the correct location but now it gives the error, so the above question doesn't really matter

"FormatException: The specified format 'D04' is invalid"

So I changed the D04 to 004 and it only takes one screenshot.

  var name = String.Format("{0}/{1:D04} shot.png", folder, frameRate );
 Application.CaptureScreenshot(name);



How could I change this {0}/{1:D04}

to incorporate this part? As this would solve my problems.

 var info3 = new DirectoryInfo(folder);
 var fileInfo3 = info3.GetFiles();
  Application.CaptureScreenshot("Shot"+info3.GetFiles().Length +".png");




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

  • Sort: 
avatar image
0

Answer by Landern · Jul 14, 2014 at 12:21 PM

wrong format specification? Should it be "D4", meaning four decimal places from the right side.

From [Standard Numeric Format String on MSDN][1]:

The "D" (or decimal) format specifier converts a number to a string of decimal digits (0-9), prefixed by a minus sign if the number is negative. This format is supported only for integral types.

The precision specifier indicates the minimum number of digits desired in the resulting string. If required, the number is padded with zeros to its left to produce the number of digits given by the precision specifier. If no precision specifier is specified, the default is the minimum value required to represent the integer without leading zeros. Also see: [Composite Formatting][2] [1]: http://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.110).aspx#DFormatString [2]: http://msdn.microsoft.com/en-us/library/txafckwd(v=vs.110).aspx Edit: Hrm, may be another issue, ran it in VS2013 and mimic'd your code and it worked fine with leading zeros on the format specifier... :(
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 ODNSEV7N · Jul 15, 2014 at 05:03 AM 0
Share

I found that Time.frameCount will deter$$anonymous$$e the number after the 0'z.

so it's going 00Shot"Time.frameCount".png. (00Shot12.png, 00Shot53.png) etc.

Also on mobile if I take a few shots, they aren't taken, but the button that allows the user to take a screenshot disappears.

I will do a log cat I think. forgot about that heheh.

I'm thinking the syntax is correct but something else may be preventing it from working on mobiles. I'l have a play around.

avatar image ODNSEV7N · Jul 15, 2014 at 05:41 AM 0
Share

Here is what the log states.

E/Unity (20544): Failed to open file at path: /storage/sdcard0/Android/data/com.indevelope.Tandem$$anonymous$$ingz/files/storage/sdcard0/Android/data/com.indevelope.Tandem$$anonymous$$ingz/files/0560 shot.png

E/Unity (20544):

E/Unity (20544): (Filename: Line: 489)

E/Unity (20544):

E/Unity (20544): Failed to store screen shot

E/Unity (20544):

E/Unity (20544): (Filename: Line: 238)

E/Unity (20544):

I will just use a different method and see how they work. Something like:

var name = folder + info3.GetFiles().Length + "Shot.png";

Follow this Question

Answers Answers and Comments

22 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

Related Questions

Float output being rounded when unintended 1 Answer

Grab part of a string by looking for keyword 2 Answers

Restore player position using vector3 from variable. 4 Answers

TextMesh Pro Input Field Character Validation using Regex 0 Answers

Cant convert int to string in c# 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