Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 |
Tags
- 게이트 웨이
- github
- 메모리누수찾기
- 자료구조 공부
- devops
- 성능프로파일러
- 정리글
- c++메모리누수
- 정보누적
- c++ 알고리즘 공부
- window개발
- c++ 공부
- 디버깅기능
- 데브옵스
- 비트버킷
- 원격디버거
- 아이구..
- 데브옵스엔지니어
- 네트워크 비트
- 코린이
- 서브넷 마스크
- C++공부
- git
- 비쥬얼스튜디오기능
- VisualStudio
- SVN
- C++알고리즘 공부
- C++
- 호스트 비트
- 비쥬얼스튜디오
Archives
- Today
- Total
장비업체의 하급 비전개발자
비쥬얼 스튜디오(Visual Studio) C++를 이용한 화면 캡쳐해서 이미지로 저장하는 코드 본문
업무를 하면서 자료를 윈도우 캡쳐도구를 이용해서 캡쳐 후 저장하는경우가 많아서 이거를 프로그램으로 짜는걸 찾아보았다.
열심히 찾아본결과 다음과 같은 코드를 발견하여서 내 입맛대로 적용했다.
int IDC_PROFILEVIEW, IDC_IMAGEIVEW;
CString strFileName,strImageName;
strFileName.Format(_T("%sGraph%d.png"), DATA_PATH, Index);
strImageName.Format(_T("%sImage%d.png"),DATA_PATH, Index);
HDC h_dc = ::GetWindowDC(NULL);
// 캡쳐에 사용할 CImage 객체를 선언한다.
CImage graph_image,image;
// 수평 해상도를 얻는다.
int cx = ::GetSystemMetrics(SM_CXSCREEN);
// 수직 해상도를 얻는다.
int cy = ::GetSystemMetrics(SM_CYSCREEN);
CRect rtProfileview, rtImageview;
GetDlgItem(IDC_PROFILEVIEW)->GetWindowRect(&rtProfileview);
GetDlgItem(IDC_IMAGEIVEW)->GetWindowRect(&rtImageview);
// 화면의 색상 수를 얻는다.
int color_depth = ::GetDeviceCaps(h_dc, BITSPIXEL);
CRect rt;
::GetWindowRect(GetSafeHwnd(), &rt);
graph_image.Create(rtProfileview.Width(), rtProfileview.Height(), color_depth, 0);
image.Create(rtImageview.Width(), rtImageview.Height(), color_depth, 0);
// 화면 전체 이미지를 m_tips_image 객체에 복사한다.
::BitBlt(graph_image.GetDC(), 0, 0, cx, cy, h_dc, rtProfileview.left, rtProfileview.top, SRCCOPY);
::BitBlt(image.GetDC(), 0, 0, cx, cy, h_dc, rtImageview.left, rtImageview.top, SRCCOPY);
graph_image.Save((LPCTSTR)strFileName, Gdiplus::ImageFormatPNG);
image.Save((LPCTSTR)strImageName, Gdiplus::ImageFormatPNG);
// 화면 캡쳐에 사용했던 DC를 해제한다.
::ReleaseDC(NULL, h_dc);
graph_image.ReleaseDC();
image.ReleaseDC();
'c++ MFC' 카테고리의 다른 글
| 비쥬얼 스튜디오(Visual Studio) 메모리 누수 찾기 위한 좋은 기능! 성능 프로파일러 사용법 (0) | 2023.02.14 |
|---|---|
| 비쥬얼 스튜디오(Visual Studio) 내가 자주 쓰는 단축키(hotkey) (0) | 2023.02.09 |
| 비쥬얼 스튜디오(Visual Studio) c++ 원격 디버깅(remote debugging) 하는 방법 (0) | 2023.02.08 |