스크린 캡쳐 프로그램 C# 코드

10,000

Category:
Share:

모니터 ID 를 전달 받아 CLI 환경에서 모니터 전체의 스크린샷을 캡쳐하는 소스 코드 monitor_capture.cs
프로세스 ID 를 전달 받아 CLI 환경에서 해당 윈도우의 스크린샷을 캡쳐하는 소스 코드 screen_capture.cs

컴파일 방법은 아래와 같습니다.

✅ 1. .NET SDK 설치 여부 확인

dotnet –version

만약 설치되어 있지 않다면, 공식 .NET 다운로드 페이지에서 최신 .NET SDK를 설치하세요.

✅ 2. 프로젝트 구조 만들기
터미널 또는 CMD에서 다음을 실행:

mkdir MonitorCapture
cd MonitorCapture
dotnet new console

이후 Program.cs를 열고, 기존 코드로 덮어씁니다.

✅ 3. 기존 코드 붙여넣기

Program.cs 내용을 아래와 같이 변경하세요:

// Program.cs 파일 전체를 기존 코드로 교체
또는 복사한 코드를 Visual Studio Code 등의 편집기에 붙여넣으세요.

✅ 4. 컴파일 (출력 바이너리 만들기)
dotnet publish -c Release -r win-x64 –self-contained true -p:PublishSingleFile=true
옵션 설명:

-c Release: Release 모드로 컴파일

-r win-x64: Windows 64비트 실행 파일 생성

–self-contained true: .NET 런타임 없이 독립 실행 파일 생성

-p:PublishSingleFile=true: 하나의 실행 파일로 번들링

이렇게 하면 bin/Release/netX.X/win-x64/publish/ 디렉토리에 단일 실행 파일이 생성됩니다.

예: MonitorCapture.exe

✅ 5. 실행 예시
MonitorCapture.exe 1 output.png

MonitorCapture.exe 1
🔄 참고: .NET 버전 선택
.csproj에서 .NET 버전은 기본적으로 net8.0 혹은 net7.0일 수 있습니다. 구버전 호환이 필요하면 net6.0-windows 또는 net472 등의 타겟을 설정할 수도 있습니다.

예시 (.csproj 수정):


<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0-windows</TargetFramework>
    <UseWindowsForms>true</UseWindowsForms>
    <Nullable>enable</Nullable>
  </PropertyGroup>

</Project>

✅ 추가 팁
Windows 전용 앱이므로 반드시 -r win-x64 또는 win-x86으로 지정

UseWindowsForms가 true여야 System.Windows.Forms.Screen을 사용할 수 있음

GUI가 아니므로 아이콘, 폼 등을 생성하지 않아도 됨

뭐든지 물어보세요.
Select the fields to be shown. Others will be hidden. Drag and drop to rearrange the order.
  • Image
  • SKU
  • Rating
  • Price
  • Stock
  • Availability
  • Add to cart
  • Description
  • Content
  • Weight
  • Dimensions
  • Additional information
Click outside to hide the comparison bar
Compare