最近在搞WINCE,用GDI写了个半透明,其实原理就上边的大大所说,图层叠加就行了
取底图,去关键色,半透明
- //绘缓冲区DC,把shdc半透明贴到dhdc上
- void DrawCache2(HDC dhdc,RECT rect1,HDC shdc,RECT rect2)
- {
- //底图片
- HDC backhdc = CreateCompatibleDC (dhdc) ;
- HBITMAP hbitback = CreateCompatibleBitmap(dhdc,rect1.right - rect1.left,rect1.bottom - rect1.top);
- HGDIOBJ hbojtemp = SelectObject (backhdc,hbitback);
- //取底片
- BitBlt(
- backhdc,
- 0,
- 0,
- rect1.right - rect1.left,
- rect1.bottom - rect1.top,
- dhdc,
- rect1.left,
- rect1.top,
- SRCCOPY);
- //去关键色
- TransparentBlt(backhdc,
- 0,
- 0,
- rect1.right - rect1.left,
- rect1.bottom - rect1.top,
- shdc,
- rect2.left,
- rect2.top,
- rect2.right - rect2.left,
- rect2.bottom - rect2.top,
- 0);
- //*
- //半透明
- BLENDFUNCTION bf;
- bf.BlendOp = AC_SRC_OVER; //目前只有这个
- bf.BlendFlags = 0; //保留位,目前只有这个
- bf.AlphaFormat = AC_SRC_OVER; //这个参数是指定加载自带Alpha通道
- bf.SourceConstantAlpha = 127; //如果上面用了自带通道,那这个值就没意义
- AlphaBlend(dhdc,
- rect1.left,
- rect1.top,
- rect1.right - rect1.left,
- rect1.bottom - rect1.top,
- backhdc,
- 0,
- 0,
- rect1.right - rect1.left,
- rect1.bottom - rect1.top,
- bf);
- //*/
- SelectObject(backhdc,hbojtemp);
- DeleteDC(backhdc);
- DeleteObject(hbitback);
- }