[WinAPI] AlphaBlend, 투명 출력

오늘 알아볼 AlphaBlend 함수는 투명도를 출력하여 출력하는 함수 입니다.
함수 원형은 아래와 같습니다.

BOOL AlphaBlend(
	HDC	hdcDest, // 출력 DC
	int	xoriginDest, // x좌표
	int	yoriginDest, // y좌표
	int	wDest, // width
	int	hDest, // height
	HDC	hdcSrc, // 원본
	int	xoriginSrc, // x좌표
	int	yoriginSrc, // y좌표
	int	wSrc, // width
	int	hSrc, // height
	BLENDFUNCTION ftn // BLENDFUNCTION 구조체
);

BLENDFUNCTION 구조체는 선언하여 아래와 같이 사용합니다.

// BLENDFUNCTION 구조체
BLENDFUNCTION bf;
bf.AlphaFormat = 0; // 일반 비트맵 0, 32비트 비트맵 AC_SRC_ALPHA
bf.BlendFlags = 0; // 무조건 0
bf.BlendOp = AC_SRC_OVER; // AC_SRC_OVER
bf.SourceConstantAlpha = 100; // 투명도(투명 0 - 불투명 255)

예제 코드는 아래와 같습니다.
CImage를 이용하여 Temp HDC에 저장하고, AlphaBlend를 이용하여 투명도를 조절하여 HDC에 출력합니다.

CImage imgFile;
HRESULT hr = imgFile.Load(m_sSelectImgPath);

HDC hdc = ::GetDC(m_stDisp.m_hWnd);
HDC hdcTemp = ::CreateCompatibleDC(hdc);
HBITMAP hbmp = ::CreateCompatibleBitmap(hdc, imgFile.GetWidth(), imgFile.GetHeight());
::SelectObject(hdcTemp, hbmp);

imgFile.Draw(hdcTemp, 0, 0, imgFile.GetWidth(), imgFile.GetHeight());

// BLENDFUNCTION 구조체
BLENDFUNCTION bf;
bf.AlphaFormat = 0; // 일반 비트맵 0, 32비트 비트맵 AC_SRC_ALPHA
bf.BlendFlags = 0; // 무조건 0
bf.BlendOp = AC_SRC_OVER; // AC_SRC_OVER
bf.SourceConstantAlpha = 100; // 투명도(투명 0 - 불투명 255)

::AlphaBlend(hdc, 0, 0, imgFile.GetWidth(), imgFile.GetHeight(),
	hdcTemp,0, 0, imgFile.GetWidth(), imgFile.GetHeight(), bf);

::DeleteObject(hbmp);
::DeleteDC(hdcTemp);

이미지를 출력하는 테스트 예제로 제가 좋아하는 가수, 아이유 사진으로 해봤습니다.

일반적인 BitBlt를 사용하면 아래와 같이 출력합니다.

하지만 BLENDFUNCTION에 투명도를 입력해서 AlphaBlend를 사용하면 아래와 같이 출력합니다.

뒤에 있던 글자가 보입니다.

이상으로 AlphaBlend에 대해 알아봤습니다.