説明なし
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

拍照測試1.cs 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.SceneManagement;
  5. using UnityEngine.UI;
  6. using UnityEngine.Networking;
  7. using System.Text.RegularExpressions;
  8. using System.Data.SqlClient;
  9. using TMPro;
  10. using System;
  11. using System.IO;
  12. using ZXing;
  13. using ZXing.QrCode;
  14. using System.Net;
  15. using SimpleJSON;
  16. using System.ComponentModel;
  17. using System.Runtime.InteropServices;
  18. public class 拍照測試1 : MonoBehaviour
  19. {
  20. [SerializeField] GameObject 主要;
  21. [SerializeField] GameObject 次要;
  22. [SerializeField] RawImage rowImage;
  23. [SerializeField] RawImage rowImage1;
  24. private WebCamTexture webCamTexture;//接收攝影機返回的圖片數據
  25. public CanvasScaler canvasScaler;
  26. // Start is called before the first frame update
  27. void Start()
  28. {
  29. 主要.SetActive(true);
  30. 次要.SetActive(false);
  31. WebCamDevice[] devices = WebCamTexture.devices;
  32. if (devices.Length > 0)
  33. {
  34. webCamTexture = new WebCamTexture(devices[0].name, 1280, 1080); // 设定相机的分辨率
  35. rowImage.texture = webCamTexture;
  36. // 开始捕获相机图像
  37. webCamTexture.Play();
  38. }
  39. }
  40. public void OnCapturePhotoButtonClicked()
  41. {
  42. if (webCamTexture != null)
  43. {
  44. Texture2D photoTexture = new Texture2D(webCamTexture.width, webCamTexture.height);
  45. photoTexture.SetPixels(webCamTexture.GetPixels());
  46. photoTexture.Apply();
  47. // 将拍摄到的照片显示在 RawImage 上
  48. rowImage1.texture = photoTexture;
  49. }
  50. webCamTexture.Stop();
  51. webCamTexture = null;
  52. Main.Global.鏡頭啟動=false;
  53. rowImage.texture = Texture2D.blackTexture;
  54. 主要.SetActive(false);
  55. 次要.SetActive(true);
  56. }
  57. public void SavePhoto()
  58. {
  59. Texture2D photoTexture = (Texture2D)rowImage1.texture;
  60. byte[] photoBytes = photoTexture.EncodeToJPG(); // You can also use EncodeToPNG
  61. string filePath = Path.Combine(Application.persistentDataPath, "capturedPhoto.jpg");
  62. File.WriteAllBytes(filePath, photoBytes);
  63. }
  64. public void 上頁()
  65. {
  66. 主要.SetActive(true);
  67. 次要.SetActive(false);
  68. }
  69. public void back()
  70. {
  71. change_Secen(1);
  72. }
  73. public void change_Secen(int _screenNum)
  74. {
  75. SceneManager.LoadScene(_screenNum);
  76. }
  77. }