位图去空白

显示位图并去掉位图周围空白区域:

需要调用函数:TransparentBlt

具体参见:http://baike.baidu.com/view/1080409.htm?fr=ala0_1

  函数功能:该函数对指定的源设备环境中的矩形区域像素的颜色数据进行位块(bit_block)转换,并将结果置于目标设备环境。

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

  参数:

  hdcDest:指向目标设备环境的句柄。

  nXOriginDest:指定目标矩形左上角的X轴坐标,坐标以逻辑单位表示。

  nYOriginDest:指定目标矩形左上角的Y轴坐标,坐标以逻辑单位表示。

  nWidthDest:指定目标矩形的宽度。

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

  hdcsrc:指向源设备环境的句柄。

  nXOriginSrc:指定源矩形(左上角)的X轴坐标,坐标以逻辑单位表示。

  nYOriginsrc:指定源矩形(左上角)的Y轴坐标,坐标以逻辑单位表示。

  nWidthSrc:指定源矩形的宽度。

  nHeightSrc:指定源矩形的高度。

  crTransparent:源位图中的RGB值当作透明颜色。返回值:如果函数执行成功,那么返回值为TRUE;如果函数执行失败,那么返回值为FALSE。

样例:

代码
void CExampleView::Draw(int nx,int ny)
{
CDC
*pDC=GetDC();

CBitmap bitmap;
bitmap.LoadBitmapW(IDB_BITMAP1);

CDC dcCompatible;
dcCompatible.CreateCompatibleDC(pDC);

dcCompatible.SelectObject(
&bitmap);

TransparentBlt(pDC
->m_hDC, //CDC 转成 HDC
(nx+1)*30-14,
(ny
+1)*30-14,
28,
28,
dcCompatible1.m_hDC,
0,
0,
28,
28,
RGB(
255,255,255));
}
原文地址:https://www.cnblogs.com/submarinex/p/1941235.html