根据bmp设置窗口轮廓

HRGN CLaucherApp::BitmaoToRegion(HBITMAP _hBitMap)
{

     BITMAP * bitMap;        // BITMAP 对象,用于储存BITMAP信息 
     BYTE * BMP;             // BMP数组,储存BITMAP的RGB信息数组 
     POINT * leftPoint;      // 左 POINT数组,储存获得的点信息 
     POINT * rightPoint;     // 右POINT数组,储存获得的点信息 
     POINT * point;          // POINT 数组,储存获得的点信息 
     int index = 0;          // POINT数组索引 
     int bmpIndex = 0;       // BMP数组索引 
     COLORREF color;         // 透明颜色值 
     bitMap = new BITMAP(); 
     GetObject(_hBitMap, sizeof(BITMAP),bitMap); 
     int bytesPix = bitMap->bmBitsPixel/8; 
     int count = bitMap->bmHeight*bitMap->bmWidth*bytesPix;  
     BMP = new BYTE[count]; 
     leftPoint = new POINT[bitMap->bmHeight]; 
     rightPoint = new POINT[bitMap->bmHeight]; 
     GetBitmapBits(_hBitMap,count, BMP); 
     // 设置左上角第一个像素颜色为默认透明色 
     color = RGB(BMP[2],BMP[1],BMP[0]);  
     // 左边轮廓扫描 
     for (int row=0; row<bitMap->bmHeight; row +=1) 
     { 
         for (int col=0; col<bitMap->bmWidth*bytesPix; col+=4) 
         { 
             bmpIndex = row*bitMap->bmWidth*bytesPix + col; 
             if(BMP[bmpIndex] != GetBValue(color) || BMP[bmpIndex+1] != GetGValue(color) || BMP[bmpIndex+2] != GetRValue(color)) 
             { 
                 leftPoint[index].x = (col/4)%bitMap->bmWidth; 
                 leftPoint[index].y = row; 
                 index++; 
                 break; 
             } 
         } 
     } 
     // 右边轮廓扫描 
     index = 0; 
     for (int row=0; row<bitMap->bmHeight; row+=1) 
     { 
         for (int col=bitMap->bmWidth*bytesPix-1; col>=0; col-=4) 
         { 
             bmpIndex = row*bitMap->bmWidth*bytesPix + col; 
             if(BMP[bmpIndex-3] != GetBValue(color) || BMP[bmpIndex-2] != GetGValue(color) || BMP[bmpIndex-1] != GetRValue(color)) 
             { 
                 rightPoint[index].x = (col/4)%bitMap->bmWidth+1; 
                 rightPoint[index].y = row; 
                 index++; 
                 break; 
             } 
         } 
     } 
     point = new POINT[index*2]; 
     for(int i=0; i<index; i++) 
     { 
         point[i] = leftPoint[i]; 
         point[i+index] = rightPoint[index-i-1]; 
     } 
     HRGN hRgn = CreatePolygonRgn(point, index*2, ALTERNATE); 
      
     int start = 0; 
     int length = 0; 
    bool isStart = false; 
     for (int row=0; row<index; row +=1) 
     { 
        for (int col=leftPoint[row].x; col<rightPoint[row].x; col+=1) 
        { 
             bmpIndex = leftPoint[row].y*bitMap->bmWidth*bytesPix + col*bytesPix; 
             if(BMP[bmpIndex] == GetBValue(color) && BMP[bmpIndex+1] == GetGValue(color) && BMP[bmpIndex+2] == GetRValue(color)) 
             { 
                 if(!isStart) 
                 { 
                    isStart = true; 
                     start = col; 
                 } 
                length++; 
             } 
             else 
             { 
                if(isStart) 
                 { 
                     HRGN TempRgn = CreateRectRgn( 
                         start%bitMap->bmWidth, 
                         leftPoint[row].y, 
                        (start+length)%bitMap->bmWidth, 
                        leftPoint[row].y+1); 
                    CombineRgn(hRgn, hRgn, TempRgn, RGN_XOR);   
                     DeleteObject(TempRgn); 
                    start = start+length; 
                    length = 0; 
                    isStart = false; 
                 } 
             } 
         } 
     }    
     delete point; 
     delete leftPoint; 
     delete rightPoint; 
     delete BMP; 
     delete bitMap; 
     return hRgn; 
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值