C, C++
Console 어플리케이션에 이미지 디스플레이 하기
J-sean
2018. 11. 22. 15:48
반응형
Console에 이미지를 디스플레이 하는 간단한 코드.
윈도우 어플리케이션처럼 이미지가 지워졌을때 다시 그려주는 코드가 없기 때문에 커서 이동, 마우스 클릭등으로 이미지가 지워져도 다시 그려주지는 않는다.
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 31 | #include<stdio.h> #include<Windows.h> int main(void) { printf("Image loading...\n"); Sleep(100); // 콘솔이 나타날때까지 잠시 멈추지 않으면 이미지가 표시되지 않는 경우가 생긴다. HWND hWnd = GetConsoleWindow(); // Retrieves the window handle used by the console associated with the calling process. HBITMAP hImage, hOldBitmap; HDC hDC = GetDC(hWnd); HDC hMemDC = CreateCompatibleDC(hDC); hImage = (HBITMAP)LoadImage(NULL, TEXT("cat.bmp"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION); // Loads an icon, cursor, animated cursor, or bitmap. hOldBitmap = (HBITMAP)SelectObject(hMemDC, hImage); BitBlt(hDC, 50, 50, 50 + 612, 50 + 409, hMemDC, 0, 0, SRCCOPY); // Image(612, 409) at (50, 50) // The BitBlt function performs a bit-block transfer of the color data corresponding to a rectangle of pixels // from the specified source device context into a destination device context. SelectObject(hMemDC, hOldBitmap); DeleteObject(hImage); DeleteDC(hMemDC); ReleaseDC(hWnd, hDC); return 0; } | cs |
결과:
반응형