using UnityEngine; using System; using System.IO; using System.Windows.Forms; using System.Drawing; using System.Drawing.Imaging; using Screen = System.Windows.Forms.Screen; using Graphics = System.Drawing.Graphics; public class TakeScreen : MonoBehaviour { // 캡처할 모니터 인덱스 (0 = 첫번째 모니터) public int monitorIndex = 0; [SerializeField] DirectorySelect directorySelector; private void Start() { // 연결된 모니터 목록 Debug.Log ("displays connected: " + Display.displays.Length); // Display.displays[0] is the primary, default display and is always ON, so start at index 1. // Check if additional displays are available and activate each. for (int i = 1; i < Display.displays.Length; i++) { Display.displays[i].Activate(); } } void Shot() { CaptureMonitor(monitorIndex, directorySelector.selectedFolderPath); Debug.Log($"Monitor {monitorIndex} 캡처 완료 : {directorySelector.selectedFolderPath}"); } void CaptureMonitor(int index, string savePath) { // 연결된 모니터 목록 Screen[] screens = Screen.AllScreens; if (index < 0 || index >= screens.Length) { Debug.Log("잘못된 모니터 인덱스입니다."); return; } // 해당 모니터 정보 Screen targetScreen = screens[index]; Rectangle bounds = targetScreen.Bounds; // 비트맵 생성 using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height)) { using (Graphics g = Graphics.FromImage(bitmap)) { g.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size); } // png로 저장 bitmap.Save(savePath, ImageFormat.Png); } } }