天天看點

MFC使用TransparentBlt透明貼圖

MFC讀取一張Bmp圖時,圖檔不是透明背景時,使用TransparentBlt可對特定背景顔色進行過濾。

函數原型:BOOL TransparentBlt(HDC hdcDest, int nXOriginDest, int nYOriginDest, int nWidthDest, int hHeightDest, HDC hdcSrc, int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc, UINT crTransparent);

參數:

nXOriginDest:指定目标矩形左上角的X軸坐标,坐标以邏輯機關表示。

nYOriginDest:指定目标矩形左上角的Y軸坐标,坐标以邏輯機關表示。

nHeightDest:指定目标矩形的高度。

nXOriginSrc:指定源矩形(左上角)的X軸坐标,坐标以邏輯機關表示。

nYOriginsrc:指定源矩形(左上角)的Y軸坐标,坐标以邏輯機關表示。

nWidthSrc:指定源矩形的寬度。

nHeightSrc:指定源矩形的高度。

crTransparent:源

​​位圖​​中的RGB值當作透明顔色。(用RGB(0,0,0)也就是黑色不行)傳回值:如果函數執行成功,那麼傳回值為TRUE;如果函數執行失敗,那麼傳回值為FALSE。

使用方法如下:

1.添加頭檔案:#include <windows.h>。

2.添加Msimg32.lib。   工程---屬性---配置屬性---連結器---輸入---附加依賴項:加上lib檔案名。

TransparentBlt( hdcDest, nX, nY, nWidth, nHeight, hdcImageStore, nSrcX, nSrcY, nWidth, nHeight, nBkColor );      

nX,nY是圖檔左上角相對螢幕左上角為原點的X,Y坐标,說明圖檔要放置的位置