- Home /
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
Answer by KrisCadle · May 24, 2011 at 10:04 PM
// 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);
}
}
}
I can't find the image file resulting from this script. Is it only visible to the application and not in the file system?
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.
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.
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
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. $$anonymous$$ostly 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 ;)
Answer by Slyrfecso · Jan 26, 2012 at 03:33 PM
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
well, if you copy/pasted the code above into a javascript file, that's going to cause a few problems.
Answer by siberman · Feb 18, 2012 at 02:08 AM
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.
Your answer
Follow this Question
Related Questions
Screenshot function not working properly ,it records button on UI ? 0 Answers
Disabling all Cameras Android/Iphone 1 Answer
Setup for iPhone portrait game 0 Answers
Open/Start Device Native Camera in Unity3D app using C# script, Without 3rd Party Plugins 1 Answer
iPhone joypad interfering with MouseLook 0 Answers