알파블렌딩(Alpha Blending) 실습

* 알파블렌딩(Alpha Blending) 실습
- 윈도우 API에서 제공하는 알파 블렌딩 기능을 구현한 예제
- 비트맵 이미지 렌더와 같이 할파 블렌딩할 구역을 지정하여(잘라서) 구현 할 수 있도록 처리
* 알파 블렌딩 함수 선언
LPIMAGE_INFO _blendImage; //알파블렌드 이미지
BLENDFUNCTION _blendFunc; //알파블렌드 기능
* 알파 블렌딩 초기화 함수 몸체
HRESULT image::initForAlphaBlend()
{
//DC 가져오기
HDC hdc = GetDC(_hWnd);
//알파블렌드 옵션 초기화
_blendFunc.BlendOp = AC_SRC_OVER;
_blendFunc.BlendFlags = 0;
_blendFunc.AlphaFormat = 0;
//이미지 정보 구조체 새로 생성후 초기화 하기
_blendImage = new IMAGE_INFO;
_blendImage->loadType = LOAD_FILE;
_blendImage->resID = 0;
_blendImage->hMemDC = CreateCompatibleDC(hdc);
_blendImage->hBit = (HBITMAP)CreateCompatibleBitmap(hdc, _imageInfo->width, _imageInfo->height);
_blendImage->hOBit = (HBITMAP)SelectObject(_blendImage->hMemDC, _blendImage->hBit);
_blendImage->width = WINSIZEX;
_blendImage->height = WINSIZEY;
//DC 해제
ReleaseDC(_hWnd, hdc);
return S_OK;
}
* 알파 블렌딩 함수 몸체
void image::alphaRender(HDC hdc, int destX, int destY, int sourX, int sourY, int sourWidth, int sourHeight, BYTE alpha)
{
//알파블렌드를 사용할 수 있도록 초기화 해라
if (!_blendImage) this->initForAlphaBlend();
//알파값 초기화
_blendFunc.SourceConstantAlpha = alpha;
if (_isTrans)//배경색 없애고 출력할거냐
{
//BitBlt : DC간의 영역끼리 고속복사 해주는 함수
BitBlt(_blendImage->hMemDC, 0, 0, _imageInfo->width, _imageInfo->height, hdc, destX, destY, SRCCOPY);
GdiTransparentBlt(hdc, 0, 0, _imageInfo->width, _imageInfo->height, _imageInfo->hMemDC, 0, 0, _imageInfo->width, _imageInfo->height, _transColor);
//원본 이미지 그대로 알파블렌딩 할꺼냐?
AlphaBlend(hdc, destX, destY, sourWidth, sourHeight, _imageInfo->hMemDC, sourX, sourY, sourWidth, sourHeight, _blendFunc);
}
else//원본 이미지 그대로 출력(배경색도 출력할거냐)
{
//원본 이미지 그대로 알파블렌딩 할꺼냐?
AlphaBlend(hdc, destX, destY, sourWidth, sourHeight, _imageInfo->hMemDC, sourX, sourY, sourWidth, sourHeight, _blendFunc);
}
}
댓글
댓글 쓰기