학습목표    1

학습주제    1

예습내용    1

실습방법    1

        1

중요함수    1

비트멥 그래픽

학습목표

애니메이션 프로그램의 준비 과정으로 그래픽 파일을 올리고 확대 축소하는 방법을 배운다.

학습주제

이장은 학생들의 흥미를 일으키기 위한 단원으로 게임에 관심 있는 학생들에게 애니메이션 제작의 기초 과정을 공부 합니다.

1.       비트맵 그래픽 보기

2.       그림의 축소와 확대

예습내용

애니메이션 과정은 “VISUAL C++ 6,김용성,영진출판사 내용(P573~P593) 가지고 수업 합니다.

자세한 내용은 책을 참조 하세요.

 

실습방법

   

1. 비트멥의 출력

 

 

“man.bmp” 파일을 BMP.dsw 있는 “res” 디렉토리로 복사를 한다.

그림파일 내려받기

리소스에 그림을 등록한다.

리소스에서 추가할 *.bmp 파일을 선택한다.

다음은 리소스에 추가된 파일의 Properties 것이다.

아래와 같이 OnDraw 함수를 수정하면 그림이 나타나는 것을 있다.

 

void CBMPView::OnDraw(CDC* pDC)

{

              // 호환성 있는 메모리 DC 생성

              CDC MemDC;

              MemDC.CreateCompatibleDC(pDC);

 

              // 리소스에서 비트맵을 읽어 들여 DC 선택

              CBitmap bitmap;

              bitmap. LoadBitmap(IDB_MAN);

              CBitmap *pOldBitmap = (CBitmap *)MemDC.SelectObject(&bitmap);

 

              // 비트맵 블록 전송

              pDC->BitBlt(50, 50, 128, 32, &MemDC, 0, 0, SRCCOPY);

 

              // DC 복원

              MemDC.SelectObject(pOldBitmap);

}

 

2. 비트멥의 확대와 축소

OnDraw 함수를 아래 예제와 같이 하면 변화된 그림을 있다.

 

void CBMPView::OnDraw(CDC* pDC)

{

              // 호환성 있는 메모리 DC 생성

              CDC MemDC;

              MemDC.CreateCompatibleDC(pDC);

 

              // 리소스에서 비트맵을 읽어 들여 DC 선택

              CBitmap bitmap;

              bitmap. LoadBitmap(IDB_MAN);

              CBitmap *pOldBitmap = (CBitmap *)MemDC.SelectObject(&bitmap);

 

              // 비트맵 블록 전송

              pDC->BitBlt(50, 50, 32, 32, &MemDC, 0, 0, SRCCOPY);

              // 좌우 방향 전환

              pDC->StretchBlt(100, 50, 32, 32, &MemDC, 32, 0, -32, 32, SRCCOPY);

              // 상하좌우로 뒤집어 출력

              pDC->StretchBlt(150, 50, 32, 32, &MemDC, 32, 32, -32, -32, SRCCOPY);

              // 2 확대하여 출력

              pDC->StretchBlt(200, 50, 64, 64, &MemDC, 0, 0, 32, 32, SRCCOPY);

 

              // DC 복원

              MemDC.SelectObject(pOldBitmap);

}

 

처음

   

 

중요함수

CDC::BitBlt 

BOOL BitBlt( int x, int y, int nWidth, int nHeight, CDC* pSrcDC, int xSrc, int ySrc, DWORD dwRop );

Return Value

Nonzero if the function is successful; otherwise 0.

Parameters

x

Specifies the logical x-coordinate of the upper-left corner of the destination rectangle.

y

Specifies the logical y-coordinate of the upper-left corner of the destination rectangle.

nWidth

Specifies the width (in logical units) of the destination rectangle and source bitmap.

nHeight

Specifies the height (in logical units) of the destination rectangle and source bitmap.

pSrcDC

Pointer to a CDC object that identifies the device context from which the bitmap will be copied. It must be NULL if dwRop specifies a raster operation that does not include a source.

xSrc

Specifies the logical x-coordinate of the upper-left corner of the source bitmap.

ySrc

Specifies the logical y-coordinate of the upper-left corner of the source bitmap.

dwRop

Specifies the raster operation to be performed. Raster-operation codes define how the GDI combines colors in output operations that involve a current brush, a possible source bitmap, and a destination bitmap. The following lists raster-operation codes for dwRop and their descriptions:

  • BLACKNESS   Turns all output black.
  • DSTINVERT   Inverts the destination bitmap.
  • MERGECOPY   Combines the pattern and the source bitmap using the Boolean AND operator.
  • MERGEPAINT   Combines the inverted source bitmap with the destination bitmap using the Boolean OR operator.
  • NOTSRCCOPY   Copies the inverted source bitmap to the destination.
  • NOTSRCERASE   Inverts the result of combining the destination and source bitmaps using the Boolean OR operator.
  • PATCOPY   Copies the pattern to the destination bitmap.
  • PATINVERT   Combines the destination bitmap with the pattern using the Boolean XOR operator.
  • PATPAINT   Combines the inverted source bitmap with the pattern using the Boolean OR operator. Combines the result of this operation with the destination bitmap using the Boolean OR operator.
  • SRCAND   Combines pixels of the destination and source bitmaps using the Boolean AND operator.
  • SRCCOPY   Copies the source bitmap to the destination bitmap.
  • SRCERASE   Inverts the desination bitmap and combines the result with the source bitmap using the Boolean AND operator.
  • SRCINVERT   Combines pixels of the destination and source bitmaps using the Boolean XOR operator.
  • SRCPAINT   Combines pixels of the destination and source bitmaps using the Boolean OR operator.
  • WHITENESS   Turns all output white.

For a complete list of raster-operation codes, see About Raster Operation Codes in the Appendices section of the Win32 SDK Programmer’s Reference.

Remarks

Copies a bitmap from the source device context to this current device context.

The application can align the windows or client areas on byte boundaries to ensure that the BitBlt operations occur on byte-aligned rectangles. (Set the CS_BYTEALIGNWINDOW or CS_BYTEALIGNCLIENT flags when you register the window classes.)

BitBlt operations on byte-aligned rectangles are considerably faster than BitBlt operations on rectangles that are not byte aligned. If you want to specify class styles such as byte-alignment for your own device context, you will have to register a window class rather than relying on the Microsoft Foundation classes to do it for you. Use the global function AfxRegisterWndClass.

GDI transforms nWidth and nHeight, once by using the destination device context, and once by using the source device context. If the resulting extents do not match, GDI uses the Windows StretchBlt function to compress or stretch the source bitmap as necessary.

If destination, source, and pattern bitmaps do not have the same color format, the BitBlt function converts the source and pattern bitmaps to match the destination. The foreground and background colors of the destination bitmap are used in the conversion.

When the BitBlt function converts a monochrome bitmap to color, it sets white bits (1) to the background color and black bits (0) to the foreground color. The foreground and background colors of the destination device context are used. To convert color to monochrome, BitBlt sets pixels that match the background color to white and sets all other pixels to black. BitBlt uses the foreground and background colors of the color device context to convert from color to monochrome.

Note that not all device contexts support BitBlt. To check whether a given device context does support BitBlt, use the GetDeviceCaps member function and specify the RASTERCAPS index.