• 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 /
avatar image
3
Question by ina · Apr 22, 2011 at 06:58 AM · androidcameraiphonescreenshotoverlay

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

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

3 Replies

· Add your reply
  • Sort: 
avatar image
2

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);
         }
     }
 }

 
Comment
Add comment · Show 6 · 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 cmauceri · Jan 21, 2012 at 02:57 PM 0
Share

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

avatar image ina · Jan 21, 2012 at 04:47 PM 0
Share

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.

avatar image cmauceri · Jan 21, 2012 at 04:54 PM 0
Share

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.

avatar image ina · Jan 21, 2012 at 04:58 PM 0
Share

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

avatar image KrisCadle · Mar 28, 2012 at 09:11 PM 0
Share

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 ;)

Show more comments
avatar image
0

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

Comment
Add comment · Show 1 · 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 Lo0NuhtiK · Jan 26, 2012 at 03:35 PM 1
Share

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

avatar image
0

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.

Comment
Add comment · 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

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How does WebcamTexture work? 0 Answers

Created a Vertical game for iPhone / Android 2 Answers

Mapping accelerometer to Camera's position 2 Answers

Take a Screenshot and Automatically have it Emailed to My Email (Android/iPhone) 0 Answers

Mobile Device Video Camera 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