文档库 最新最全的文档下载
当前位置:文档库 › 半透明(wince)

半透明(wince)

{

HDC hBackDC;
hBackDC = CreateCompatibleDC(hDC);
HBITMAP hBackBitmap;
//hBackBitmap = (HBITMAP)LoadImage(NULL,_T("\\SD 卡\\hmain.bmp"),IMAGE_BITMAP,0,0,0);
hBackBitmap = (HBITMAP)SHLoadDIBitmap(_T("\\SD_Card\\hmain.bmp"));
SelectObject(hBackDC,hBackBitmap);

HBITMAP hUpBitmap;
HDC hUpDC;
hUpDC = CreateCompatibleDC(hDC);
//hUpBitmap = (HBITMAP)LoadImage(NULL,_T("\\SD 卡\\1.bmp"),IMAGE_BITMAP,0,0,0);
hUpBitmap = (HBITMAP)SHLoadDIBitmap(_T("\\SD_Card\\1.bmp"));
SelectObject(hUpDC,hUpBitmap);


int nWidth = rect.right - rect.left; //半透明区域的宽度
int nHeight = rect.bottom - rect.top; //半透明区域的高度

//新建一个DC来拷贝目标区域
HDC BackDC;
BackDC = CreateCompatibleDC(hBackDC);
HBITMAP BackBitmap ;
BackBitmap = CreateCompatibleBitmap(hBackDC , nWidth , nHeight);
HBITMAP hOldBmp =(HBITMAP)SelectObject(BackDC,BackBitmap);
BitBlt(BackDC , 0 , 0 , nWidth , nHeight , hBackDC , rect.left , rect.top , SRCCOPY);


//获取BackDC中的图形数据到BYTE数组
HDC hBackDIBDC = CreateCompatibleDC(BackDC);

BITMAPINFO hdr;
ZeroMemory(&hdr , sizeof(BITMAPINFO));

hdr.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
hdr.bmiHeader.biWidth = nWidth;
hdr.bmiHeader.biHeight = nHeight;
hdr.bmiHeader.biPlanes = 1;
hdr.bmiHeader.biBitCount = 24;

BYTE * pBuffer = NULL ;
HBITMAP hBackDIBitmap = CreateDIBSection(hBackDIBDC,
(BITMAPINFO *)&hdr,
DIB_RGB_COLORS,
(void **)&pBuffer,
NULL,
0);

HBITMAP pOldBmp = (HBITMAP)SelectObject(hBackDIBDC, hBackDIBitmap);
BitBlt(hBackDIBDC,0,0,nWidth,nHeight,BackDC,0,0,SRCCOPY);
SelectObject(hBackDIBDC, pOldBmp);

//新建一个DC来拷贝目标区域
HDC UpDC;
UpDC = CreateCompatibleDC(hUpDC);
HBITMAP UpBitmap ;
UpBitmap = CreateCompatibleBitmap(hUpDC , nWidth , nHeight);
HBITMAP hOldBmp1 =(HBITMAP)SelectObject(UpDC,UpBitmap);
BitBlt(UpDC , 0 , 0 , nWidth , nHeight , hUpDC , rect.left , rect.top , SRCCOPY);


//获取UpDC中的图形数据到BYTE数组
HDC hUpDIBDC = CreateCompatibleDC(UpDC);



BYTE * pBuffer1 = NULL ;
HBITMAP hUpDIBitmap = CreateDIBSection(hUpDIBDC,
(BITMAPINFO *)&hdr,

DIB_RGB_COLORS,
(void **)&pBuffer1,
NULL,
0);

HBITMAP pOldBmp1 = (HBITMAP)SelectObject(hUpDIBDC, hUpDIBitmap);
BitBlt(hUpDIBDC,0,0,nWidth,nHeight,UpDC,0,0,SRCCOPY);
SelectObject(hUpDIBDC, pOldBmp1);



int PixelBytes = 3;

for( int i = 0; i < nHeight;i ++)
for(int j = 0; j < nWidth; j ++)
{
BYTE btB = pBuffer[i * nWidth * PixelBytes + j * PixelBytes ] ;
BYTE btG = pBuffer[i * nWidth * PixelBytes + j * PixelBytes + 1 ] ;
BYTE btR = pBuffer[i * nWidth * PixelBytes + j * PixelBytes + 2 ] ;

BYTE btSB = pBuffer1[i * nWidth * PixelBytes + j * PixelBytes ];

BYTE btSG = pBuffer1[i * nWidth * PixelBytes + j * PixelBytes + 1];

BYTE btSR = pBuffer1[i * nWidth * PixelBytes + j * PixelBytes ];

btB = (BYTE) (btSB * Trans + (1-Trans) * btB);
btG = (BYTE) (btSG * Trans + (1-Trans) * btG);
btR = (BYTE) (btSR * Trans + (1-Trans) * btR);

pBuffer[i * nWidth * PixelBytes + j * PixelBytes ] = btB ;
pBuffer[i * nWidth * PixelBytes + j * PixelBytes + 1 ] = btG ;
pBuffer[i * nWidth * PixelBytes + j * PixelBytes + 2 ] = btR ;

}
StretchDIBits(hDC,rect.left,rect.top,nWidth,nHeight,
rect.left,rect.left,nWidth,nHeight,pBuffer,(LPBITMAPINFO)&hdr,DIB_RGB_COLORS,SRCCOPY);

}

相关文档
相关文档 最新文档