Skip to content
조회 수 3947 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

파이썬으로 비활성화 된 창의 이미지를 캡쳐하는 방법

 

 

 

Python으로 비활성화된 창 이미지를 캡처하려면

 

pywin32 패키지의

win32gui 및 win32ui 모듈을 사용할 수 있습니다.

 

다음은 캡처 방법을 보여주는 코드 스니펫의 예입니다.

Capturing an image of a disabled window with Python can be accomplished by using the win32gui and win32ui modules from the pywin32 package. Here's an example code snippet that demonstrates how to capture a screenshot of a disabled window:

 
python
import win32gui
import win32ui
import win32con
 
# Get the handle of the disabled window
hwnd = win32gui.FindWindow(None, "Window Title")
win32gui.EnableWindow(hwnd, False)
 
# Get the dimensions of the window
left, top, right, bottom = win32gui.GetWindowRect(hwnd)
width = right - left
height = bottom - top
 
# Create a device context for the window
hwnd_dc = win32gui.GetWindowDC(hwnd)
mfc_dc = win32ui.CreateDCFromHandle(hwnd_dc)
save_dc = mfc_dc.CreateCompatibleDC()
 
# Create a bitmap to store the screenshot
bitmap = win32ui.CreateBitmap()
bitmap.CreateCompatibleBitmap(mfc_dc, width, height)
save_dc.SelectObject(bitmap)
 
# Copy the pixels from the window to the bitmap
save_dc.BitBlt((0, 0), (width, height), mfc_dc, (0, 0), win32con.SRCCOPY)
 
# Save the screenshot as a file
bitmap.SaveBitmapFile(save_dc, "screenshot.bmp")
 
# Clean up
win32gui.DeleteObject(bitmap.GetHandle())
save_dc.DeleteDC()
mfc_dc.DeleteDC()
win32gui.ReleaseDC(hwnd, hwnd_dc)

In this code, we first obtain the handle of the disabled window using FindWindow().
We then disable the window using EnableWindow() to ensure that its contents do not change while we are taking the screenshot.
We get the dimensions of the window using GetWindowRect(), and create a device context for the window using GetWindowDC(). We create a compatible device context using CreateDCFromHandle(), and a compatible bitmap using CreateCompatibleBitmap().

We then select the bitmap into the device context using SelectObject(), and copy the pixels from the window to the bitmap using BitBlt().
Finally, we save the bitmap as a file using SaveBitmapFile(), and clean up the device contexts and handles.

 

이 코드에서는 먼저 FindWindWind()를 사용하여 비활성화된 창의 핸들을 얻습니다.
그런 다음 EnableWindow()를 사용하여 스크린샷을 촬영하는 동안 내용이 변경되지 않도록 창을 비활성화합니다.


GetWindowRect()를 사용하여 창의 치수를 구하고 GetWindowDC()를 사용하여 창에 대한 장치 컨텍스트를 만듭니다. CreateDCFromHandle()을 사용하여 호환되는 장치 컨텍스트를 만들고 CreateCompatibleBitmap()을 사용하여 호환되는 비트맵을 만듭니다.

그런 다음 SelectObject()를 사용하여 비트맵을 장치 컨텍스트로 선택하고 BitBlt()를 사용하여 창에서 비트맵으로 픽셀을 복사합니다.


마지막으로 SaveBitmapFile()을 사용하여 비트맵을 파일로 저장하고 장치 컨텍스트와 핸들을 정리합니다.

 

 

#chatGPT

로그인 후 댓글쓰기가 가능합니다.

?

List of Articles
번호 분류 제목 날짜 조회 수
2324 컴퓨터잡담 윈도우10 운영체제에 크롬브라우저를 사용할 때 웹사이트 인증서 설치하는 방법 2023.03.25 15606
2323 파이썬 파이썬에서 captCha 분석 프로그램을 만들 수 있을까? 2023.03.25 11714
2322 [Docs]스프레드시트 구글 스프레드시트에서 O열=입금완료 가 있는 행은 행 전체가 노란색으로 변하게 하기 2023.03.24 10046
2321 재미재미 수 0, 1, 3, 4, 6, 7, 8을 한 번씩만 사용하여 만든 일곱 자리 수입니다. 6750000보다 크고 6800000보다 작은 수 입니다. 일의 자리 숫자와 백의 자리 숫자의 합은 십의 자리 숫자와 같습니다. 조건4) 백의 자리 숫자는 일의 자리 숫자보다 작습니다. 위의 조건을 모두 만족하는 수를 구하시오. 2023.03.19 8854
2320 재미재미 은행에 예금한 돈 35200000원을 100만원 짜리와 10만원 짜리 수표로만 찾았더니 수표가 모두 55장이었습니다. 은행에서 찾은 100만원 짜리 수표는 몇 장입니까? 2023.03.19 7516
2319 컴퓨터잡담 녹화기 Play Mode file 2023.03.17 6779
2318 파이썬 웹 페이지에서 동적으로 생성되는 데이터 가져오는 방법 2023.03.15 6932
2317 주식 아진산업 기업분석 및 전망 2023.03.13 7444
2316 회로도전자부품 전기선 + PIR 감지기 + LED 결선도 file 2023.03.13 3646
2315 주식 디지캡 한동훈 수혜이슈와 기업분석 및 전망 2023.03.12 3191
Board Pagination Prev 1 2 3 4 5 ... 235 Next
/ 235

http://urin79.com

우린친구블로그

sketchbook5, 스케치북5

sketchbook5, 스케치북5

나눔글꼴 설치 안내


이 PC에는 나눔글꼴이 설치되어 있지 않습니다.

이 사이트를 나눔글꼴로 보기 위해서는
나눔글꼴을 설치해야 합니다.

설치 취소