Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 /
This question was closed Feb 27, 2015 at 04:27 PM by meat5000 for the following reason:

Self answered

avatar image
6
Question by 199christoff · Jan 21, 2013 at 03:58 PM · iossavewebcam

How to take a photo from a webcam?

Hi I'm having some trouble taking a photo and saving it from a webcam, ideally I'm trying to get this working on iOS.

Comment
Add comment · Show 1
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 Fattie · Mar 03, 2016 at 12:26 PM 0
Share

Full solution for 2016:

http://answers.unity3d.com/questions/909967/getting-a-web-cam-to-play-on-ui-texture-image.html#answer-910020

2 Replies

  • Sort: 
avatar image
4
Best Answer

Answer by 199christoff · Feb 02, 2013 at 09:44 AM

Just want to share this with people as they may find it useful, after some additional research and trial and error I managed to solve my query.

Feel free to use the code.

 using UnityEngine;
 using System.Collections;
 
 public class WebcamTest : MonoBehaviour {
   public string deviceName;
   WebCamTexture wct;
   
   // Use this for initialization
   void Start () {
     WebCamDevice[] devices = WebCamTexture.devices;
     deviceName = devices[0].name;
     wct = new WebCamTexture(deviceName, 400, 300, 12);
     renderer.material.mainTexture = wct;
     wct.Play();
   }
   
   // For photo varibles
   
   public Texture2D heightmap;
   public Vector3 size = new Vector3(100, 10, 100);
   
   
   void OnGUI() {      
     if (GUI.Button(new Rect(10, 70, 50, 30), "Click"))
       TakeSnapshot();
     
   }
   
   // For saving to the _savepath
   private string _SavePath = "C:/WebcamSnaps/"; //Change the path here!
   int _CaptureCounter = 0;
 
   void TakeSnapshot()
     {
       Texture2D snap = new Texture2D(wct.width, wct.height);
       snap.SetPixels(wct.GetPixels());
       snap.Apply();
 
       System.IO.File.WriteAllBytes(_SavePath + _CaptureCounter.ToString() + ".png", snap.EncodeToPNG());
       ++_CaptureCounter;
   }
 }




Comment
Add comment · Show 4 · 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 Olly · Aug 28, 2016 at 01:37 PM 0
Share

The photo is rotated on iPhone.

avatar image Fattie Olly · Aug 28, 2016 at 01:51 PM 0
Share

Hi Oily. (the above code doesn't really work) Realistically you have to get the "NatCam" plug in, it's the only real solution for using the camera in Unity. The single biggest thing missing from Unity is they have not yet done camera for android/ios. (the supplied placeholder system from Unity is a total joke.) It's just simply not possible to write your own native plugin for camera handling - it takes about 18 man-months of work. 100% of projects that need actual native camera just use natcam - as soon as it was released it was one of the handful of plugins you just have to have to work. until Unity actually make camera software, that's how it is :O

avatar image Olly Fattie · Aug 28, 2016 at 02:22 PM 0
Share

NatCam is very expensive. I've actually figure it out for Android and iOS (This afternoon).

Just checked it on 3 different platforms and it's working fine :-)

Just a $$anonymous$$or rotational issue that's fixable as the WebCamTexture lets you know how far you should rotate to be facing the correct way.

Show more comments
avatar image
0

Answer by DeveshPandey · Dec 26, 2015 at 05:04 AM

If you want to take photo from device native camera then you can use this very good plugin

http://u3d.as/8t8

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

Follow this Question

Answers Answers and Comments

15 People are following this question.

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

Related Questions

Does PersistentDataPath get overwritten on mobile? 1 Answer

WebCamTexture and VSync (iPhone 4) 3 Answers

Save game in iOS background 0 Answers

Dinamic name for data save 0 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers


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