Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System;
- using System.IO;
- public class PhotoRenderer : MonoBehaviour {
- public static PhotoRenderer instance;
- WebCamTexture webcamTexture;
- string realFolder;
- void Awake () {
- instance = this;
- }
- // Use this for initialization
- void Start () {
- realFolder = Path.Combine (Application.persistentDataPath, "test" + DateTime.Now.Millisecond.ToString() + ".png");
- Debug.Log (realFolder);
- webcamTexture = new WebCamTexture ();
- webcamTexture.Play();
- GetComponent<Renderer>().material.mainTexture = webcamTexture;
- }
- public void TakeSnapshot()
- {
- Texture2D snap = new Texture2D(webcamTexture.width, webcamTexture.height);
- snap.SetPixels(webcamTexture.GetPixels());
- snap.Apply();
- byte[] Bytes = snap.EncodeToPNG();
- // Save āšā¸āšā¸ PNG
- File.WriteAllBytes(realFolder, Bytes);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement