x


Accessing the iPhone or Android camera for screenshot with overlay

Is there a way to access the iPhone or Android Camera from within Unity - for the purpose of creating a screenshot with overlay

more ▼

asked Apr 22 '11 at 06:58 AM

ina gravatar image

ina
3.3k 492 548 597

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first
// attach this to your camera



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 > 0)
        {       
            string screenshotFilename;
            do
            {
                screenshotCount++;
                screenshotFilename = "screenshot" + screenshotCount + ".png";

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

          //  audio.Play();

            Application.CaptureScreenshot(screenshotFilename);
        }
    }
}
more ▼

answered May 24 '11 at 10:04 PM

KrisCadle gravatar image

KrisCadle
194 1 3 7

I can't find the image file resulting from this script. Is it only visible to the application and not in the file system?

Jan 21 '12 at 02:57 PM cmauceri

I guess the question is, on iOS or Android, how do you find the directory or working directory path name you are currently in.. Presumably that is where the file is saved.

Jan 21 '12 at 04:47 PM ina

I think the android file manager has limited visibility. Using the code as it's written here, I went through every file I had access to with the file manager and found nothing. When I assigned the filename using Application.persistentDataPath, the application folder popped up in the file manager with the new image file.

Jan 21 '12 at 04:54 PM cmauceri

it could also be that there are permission limitations in where the UnityPlayer on Android can write to... in that case, things get more complicated and perhaps you really do need to write a Plugin just to have it write to the android gallery path

Jan 21 '12 at 04:58 PM ina

well, I had the same problem, but the images are actually there in a folder on the SD card (set force SD card permission) - but the phone gallery can't see them until the phone is plugged in to the computer and then turned back to SD card (then it sees them) or you can turn the phone off and back on I think that would work. Mostly it's not working because I take a picture , then I flip over to the gallery to look for it right away and it's not there... But it is there, you have to re-initialize the SD card... I think ;)

Mar 28 '12 at 09:11 PM KrisCadle
(comments are locked)
10|3000 characters needed characters left

Hey,

The code seems to be doing something, but there is no photo showing up in the camera roll on iOS, where is this image being saved? is there a way to save it to the default photo director, whatever that happens to be?

Thanks

Simon.

more ▼

answered Feb 18 '12 at 02:08 AM

siberman gravatar image

siberman
31 11 13 15

(comments are locked)
10|3000 characters needed characters left

Hi!

I tried your code but I get error: Assets/Screenshoot_button.js(1,6): UCE0001: ';' expected. Insert a semicolon at the end.

If I good understod, when I toch anywhere the screen on Android device, than I can take screenshoot? Thx

more ▼

answered Jan 26 '12 at 03:33 PM

Slyrfecso gravatar image

Slyrfecso
1

well, if you copy/pasted the code above into a javascript file, that's going to cause a few problems.

Jan 26 '12 at 03:35 PM Lo0NuhtiK
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2987
x2455
x1999
x103
x33

asked: Apr 22 '11 at 06:58 AM

Seen: 5620 times

Last Updated: Aug 15 '12 at 08:13 PM