Search Unity

Capture Screenshot from iPhone and save it in documents folder.

Discussion in 'iOS and tvOS' started by qamarzaman, Apr 13, 2011.

  1. qamarzaman

    qamarzaman

    Joined:
    Jul 1, 2010
    Posts:
    85
    Hay,

    I want to Capture a screenshot with programming in iphone and save it into "Documents" Folder in iphone app's directory structure. And later use this file to send on Facebook, i have prime31's social integration plugin.

    Please give some code if possible.
     
  2. Mantas-Puida

    Mantas-Puida

    Joined:
    Nov 13, 2008
    Posts:
    1,864
  3. qamarzaman

    qamarzaman

    Joined:
    Jul 1, 2010
    Posts:
    85
    Thanks for responding mantasp,

    Application.CaptureScreenshot captures screenshots and stores it in a path specified, The problem is that i can successfully save screenshot in "Documents" folder by using path Application.dataPath.Replace("Data", "Doucments"); by using unity 1.5 . but can not save screenshot in unity 3.3 by using same code, reason is that in unity 3.3 the documents folder is not in the same place as was in unity 1.5. as i've checked it by using standard directory functions.

    I want to know where is the "Documents" folder or Resources folder in iphone app
    or how can i get the path to that folder...

    Please respond.
     
  4. qamarzaman

    qamarzaman

    Joined:
    Jul 1, 2010
    Posts:
    85
    please give some comments........
     
  5. marjan

    marjan

    Joined:
    Jun 6, 2009
    Posts:
    563
    You actually don´t need to save anything because Application.CaptureScreenshot("Screenshot.png"); saves it automatically for you.
    The problem would rather be how to access it afterwords from within unity.

    I only know how to access this from Objective c. How to get the path from within Unity without using a plugin i cannot tell in the moment, but i bet a search in the forum (or answers.unity3d.com) for "documents" should reveal a solution.

    for example this here
     
  6. Mantas-Puida

    Mantas-Puida

    Joined:
    Nov 13, 2008
    Posts:
    1,864
    In Unity iPhone 1.x there was bug, which caused to return slightly incorrect path to the Data folder. Later it was fixed and thus your script from older version doesn't work anymore. Since Unity 3.3 you can use http://unity3d.com/support/documentation/ScriptReference/Application-persistentDataPath.html to get Documents folder without any additional path manipulations.
     
  7. siberman

    siberman

    Joined:
    Oct 12, 2011
    Posts:
    31
    Hey there,

    I'm trying to capture a screen shot on iOS and just have it appear with the other pictures on the device. I found this code on Unity Answers

    using UnityEngine;
    using System.Collections;

    public class TakeScreenshot : MonoBehaviour
    {
    private int screenshotCount = 0;

    // Check for screenshot key each frame
    void Update()
    {
    // take screenshot on touch

    if (Input.touches.Length > 1)
    {
    string screenshotFilename;
    do
    {
    screenshotCount++;
    screenshotFilename = "screenshot" + screenshotCount + ".png";

    } while (System.IO.File.Exists(screenshotFilename));

    // audio.Play();

    Application.CaptureScreenshot(screenshotFilename);
    }
    }
    }

    But i can't find the file it saves (if indeed it saves one)

    Any help would be greatly appreciated.

    Thanks

    Simon
     
  8. Games-Foundry

    Games-Foundry

    Joined:
    May 19, 2011
    Posts:
    632
    Couple of modifications required if you want to retrieve the file, at least for iOS...

    screenshotFilename = "screenshot" + screenshotCount + ".png";
    screenshotFilepath = Application.persistentDataPath + "/" + screenshotFilename;

    Also, I found I had to use a waiting cycle until the file exists on the file system. Looks like CaptureScreenshot is an async function.
     
  9. giancamati

    giancamati

    Joined:
    Aug 4, 2010
    Posts:
    518
    Hi,

    I was trying to solve the same problem and I wondered if you can help me. I wrote donw that code but again I can't find the picture in the Photo section of the Ipad...

    Best,
    Giancarlo

     
  10. prawn-star

    prawn-star

    Joined:
    Nov 21, 2012
    Posts:
    77
    Hi

    When I've needed to take a screen shot, I just make a hidden button somewhere that when pressed sets the time scale to 0
    Time.timeScale - 0;

    then I can use the device to capture the screen while the game is effectivelty paused.

    Pressing the hidden button again sets the time scale back to 1 to start the game again
    Time.timeScale - 1;

    Prawn Star coming soon to Free 2 PLay
    http://www.youtube.com/watch?v=tUQATVHAlvU
     
  11. TheDanger

    TheDanger

    Joined:
    Feb 24, 2015
    Posts:
    1
    Buenas tardes, tengo el mismo problema, bueno desde iTunes, en los documentos de la aplicación si me aparece el screenshot, ahora necesito me ayude a extraer este archivo para mostrarlo en la galeria del IOS.