Log in or register to post comments

Rename screenshot

February 3, 2014 - 9:57am #1

Hi,

i've set up a button that capture the screenshot, but it always replace the one previously created.

How can i assign to a screenshot a progressive number (or like H:M:S)?

I'm using this code actually:

 

    if (GUI.Button (new Rect(0,0,150,30), "ScattaFoto")) {
        Application.CaptureScreenshot("shot.png"); //here i need to replace the name each screenshot made
 
        if (QCARRuntimeUtilities.IsPlayMode()) {
            // if in PlayMode, the screenshot will be saved
            // to the project directory
            Debug.Log ("Saved screenshot");         
        }
        else {
            // if running on Device, the screenshot will be saved
            // to the Application.persistentDataPath directory
            Debug.Log ("Saved screenshot to " + Application.persistentDataPath + "/");
        }
    }

 

thanks in advance

Rename screenshot

February 18, 2014 - 12:48am #8

Ok. The only thing that comes to my mind is to check if the Date is actually reporting a different value each time (you can log it and see the actual value), and/or if maybe the filename (using the date/time) is too long and for some reasons it gets clamped... this could explain why you always get the same.

 

Rename screenshot

February 17, 2014 - 11:40am #7

As you see my code, the name will be change in every capturing and when I test the app in unity, It works very good with multiple images ! But in Android device, when I clicked the capture button many times to capture many screenshot, I will see only the last image in application persistent datapath ... And I have nothing else in my app !! It has only a target and a model plus this button to capture screenshot .

- I will ask my question in Unity3d forum too :)

Many Thanks :)

Rename screenshot

February 17, 2014 - 11:32am #6

You need to debug and see why this happens; technically you should be able to store as many screenshots as you like, provided that the filename is not always the same (otherwise it will of course overwrite the same file).

But this is more a question for the Unity forums, as it is not really about Vuforia.

 

Rename screenshot

February 17, 2014 - 11:29am #5

Hi,

I have write this code for taking multiple screenshots in my app. It works fine in unity. But when I run my app on android device, only the last taken image will store in application persistent datapath!! How should I correct this to have all of captured images?

My code is:

void OnGUI() {
    if (GUI.Button (new Rect(100, 100, 100, 100), "Capture")) {
        string utcTime = System.DateTime.Now.TimeOfDay.ToString();
        Debug.Log(utcTime);
        string filename = "Image_" + utcTime + ".png";
        Application.CaptureScreenshot(filename);
    }            
}

Please help me,

Thank you :)

Rename screenshot

February 4, 2014 - 12:37am #4

For the Date Time format, you can check this:

http://www.csharp-examples.net/string-format-datetime/

and choose one format that you like.

Concerning the location where the image is stored, this will be in the application persistent datapath, as explained in the article I was referring to.

If you want to move the file to another location on your device storage, then you will need to do that manually, by copying the file using the C# I/O API; but this is out of scope for Vuforia.

 

 

Rename screenshot

February 3, 2014 - 1:01pm #3

Thanks, but Unity give me errors when there's a space (DateTime time, string format, string currentTime etc):

Assets/Scripts/screenshot.js(5,25): UCE0001: ';' expected. Insert a semicolon at the end.

That's this space -> DateTime time

function OnGUI() {

    if (GUI.Button (new Rect(0,0,150,30), "ScattaFoto")) {
		DateTime time = DateTime.Now;
		string format = "yy-M-d-h-mm";
		string currentTime = time.ToString(format);
		Application.CaptureScreenshot("shot-" + currentTime + ".png");
 
        if (QCARRuntimeUtilities.IsPlayMode()) {
            // if in PlayMode, the screenshot will be saved
            // to the project directory
            Debug.Log ("Saved screenshot");         
        }
        else {
            // if running on Device, the screenshot will be saved
            // to the Application.persistentDataPath directory
            Debug.Log ("Saved screenshot to " + Application.persistentDataPath + "/");
        }
    }
    
  
}

 

 

BTW i can't find the screenshot in Android Gallery, to change location i need to learn C#?

Rename screenshot

February 3, 2014 - 10:50am #2

You could replace this line:

Application.CaptureScreenshot("shot.png"); 

with:

DateTime time = DateTime.Now;
string format = "yy-M-d-h-mm";
string currentTime = time.ToString(format);

Application.CaptureScreenshot("shot-" + currentTime + ".png");

 

Note: for more information about Date/time format, see this:

http://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx

as this is not really relevant to Vuforia, it's just C# programming.

 

Log in or register to post comments