Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System;
  4. using System.IO;
  5.  
  6. public class PhotoRenderer : MonoBehaviour {
  7.  
  8. public static PhotoRenderer instance;
  9. WebCamTexture webcamTexture;
  10. string realFolder;
  11.  
  12. void Awake () {
  13. instance = this;
  14. }
  15.  
  16. // Use this for initialization
  17. void Start () {
  18.  
  19. realFolder = Path.Combine (Application.persistentDataPath, "test" + DateTime.Now.Millisecond.ToString() + ".png");
  20. Debug.Log (realFolder);
  21. webcamTexture = new WebCamTexture ();
  22. webcamTexture.Play();
  23. GetComponent<Renderer>().material.mainTexture = webcamTexture;
  24.  
  25. }
  26.  
  27. public void TakeSnapshot()
  28. {
  29.  
  30. Texture2D snap = new Texture2D(webcamTexture.width, webcamTexture.height);
  31. snap.SetPixels(webcamTexture.GetPixels());
  32. snap.Apply();
  33.  
  34. byte[] Bytes = snap.EncodeToPNG();
  35.  
  36. // Save āš€ā¸›āš‡ā¸™ PNG
  37. File.WriteAllBytes(realFolder, Bytes);
  38.  
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement