123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- using UnityEngine.UI;
- using UnityEngine.Networking;
- using System.Text.RegularExpressions;
- using System.Data.SqlClient;
- using TMPro;
- using System;
- using System.IO;
- using ZXing;
- using ZXing.QrCode;
- using System.Net;
- using SimpleJSON;
- using System.ComponentModel;
- using System.Runtime.InteropServices;
- public class 拍照測試1 : MonoBehaviour
- {
- [SerializeField] GameObject 主要;
- [SerializeField] GameObject 次要;
- [SerializeField] RawImage rowImage;
- [SerializeField] RawImage rowImage1;
- private WebCamTexture webCamTexture;//接收攝影機返回的圖片數據
-
- public CanvasScaler canvasScaler;
- // Start is called before the first frame update
- void Start()
- {
- 主要.SetActive(true);
- 次要.SetActive(false);
- WebCamDevice[] devices = WebCamTexture.devices;
- if (devices.Length > 0)
- {
- webCamTexture = new WebCamTexture(devices[0].name, 1280, 1080); // 设定相机的分辨率
- rowImage.texture = webCamTexture;
-
- // 开始捕获相机图像
- webCamTexture.Play();
- }
- }
- public void OnCapturePhotoButtonClicked()
- {
- if (webCamTexture != null)
- {
- Texture2D photoTexture = new Texture2D(webCamTexture.width, webCamTexture.height);
- photoTexture.SetPixels(webCamTexture.GetPixels());
- photoTexture.Apply();
-
- // 将拍摄到的照片显示在 RawImage 上
- rowImage1.texture = photoTexture;
- }
- webCamTexture.Stop();
- webCamTexture = null;
- Main.Global.鏡頭啟動=false;
- rowImage.texture = Texture2D.blackTexture;
- 主要.SetActive(false);
- 次要.SetActive(true);
- }
-
- public void SavePhoto()
- {
- Texture2D photoTexture = (Texture2D)rowImage1.texture;
- byte[] photoBytes = photoTexture.EncodeToJPG(); // You can also use EncodeToPNG
- string filePath = Path.Combine(Application.persistentDataPath, "capturedPhoto.jpg");
- File.WriteAllBytes(filePath, photoBytes);
- }
- public void 上頁()
- {
- 主要.SetActive(true);
- 次要.SetActive(false);
- }
- public void back()
- {
- change_Secen(1);
- }
- public void change_Secen(int _screenNum)
- {
-
- SceneManager.LoadScene(_screenNum);
- }
-
-
- }
|