NO

Author Topic: 3 functions for bitmaps  (Read 1297 times)

Grincheux

  • Guest
3 functions for bitmaps
« on: March 23, 2016, 08:50:01 am »
With ImageMergeHorizontalVertical The result is :
Quote
------+++++------
------+++++------
------+++++------
++++++++++++
++++++++++++
++++++++++++
------+++++------
------+++++------
------+++++------
With ImageMergeHautBas the result is :
Quote
11111
11111
11111
11111
11111
22222
22222
22222
22222
22222
With ImageMergeDroiteGauche the result is :
Quote
11111111111111111112222222222222222222222
11111111111111111112222222222222222222222
11111111111111111112222222222222222222222
11111111111111111112222222222222222222222
11111111111111111112222222222222222222222
Code: [Select]
HBITMAP ImageMergeHorizontalVertical(HBITMAP __hHorizontal,HBITMAP __hVertical)
{
HDC _hDC, _hDCMem1, _hDCMem2 ;
BITMAP _BmpHorizontal, _BmpVertical ;
HBITMAP _hBmpResult, _hBmpOld1, _hBmpOld2 ;
int _y1, _x2 ;

_hDC = GetDC(NULL) ;
if(_hDC)
{
_hDCMem1 = CreateCompatibleDC(_hDC) ;
if(_hDCMem1)
{
_hDCMem2 = CreateCompatibleDC(_hDC) ;
if(_hDCMem2)
{
GetObject(__hHorizontal,sizeof(BITMAP),&_BmpHorizontal) ;
GetObject(__hVertical,sizeof(BITMAP),&_BmpVertical) ;

_hBmpResult = CreateCompatibleBitmap(_hDC,_BmpVertical.bmHeight,_BmpHorizontal.bmWidth) ;
if(_hBmpResult)
{
_hBmpOld2 = SelectObject(_hDCMem2,_hBmpResult) ;
if(_hBmpOld2)
{
_hBmpOld1 = SelectObject(_hDCMem1,__hHorizontal) ;
if(_hBmpOld1)
{
SetStretchBltMode(_hDCMem1,COLORONCOLOR) ;
SetStretchBltMode(_hDCMem2,COLORONCOLOR) ;

_y1 = (_BmpVertical.bmHeight / 2) - (_BmpHorizontal.bmHeight / 2) ;

BitBlt(_hDCMem2,0,_y1,_BmpHorizontal.bmWidth,_BmpHorizontal.bmHeight,_hDCMem1,0,0,SRCCOPY) ;
if(SelectObject(_hDCMem1,__hVertical))
{
_x2 = (_BmpHorizontal.bmWidth / 2) - (_BmpVertical.bmWidth / 2) ;

BitBlt(_hDCMem2,_x2,0,_BmpVertical.bmWidth,_BmpVertical.bmHeight,_hDCMem1,0,0,SRCCOPY) ;
SelectObject(_hDCMem1,_hBmpOld1) ;
SelectObject(_hDCMem2,_hBmpOld2) ;
DeleteDC(_hDCMem1) ;
DeleteDC(_hDCMem2) ;
ReleaseDC(NULL,_hDC) ;
return (_hBmpResult) ;
}
else
{
DeleteObject(_hBmpResult) ;
}

SelectObject(_hDCMem1,_hBmpOld1) ;
}
SelectObject(_hDCMem2,_hBmpOld2) ;
}
}
DeleteDC(_hDCMem2) ;
}
DeleteDC(_hDCMem1) ;
}
ReleaseDC(NULL,_hDC) ;
}

return (NULL) ;
}

HBITMAP ImageMergeHautBas(HBITMAP __hHaut,HBITMAP __hBas)
{
HDC _hDC, _hDCMem1, _hDCMem2 ;
BITMAP _BmpHaut, _BmpBas ;
HBITMAP _hBmpResult, _hBmpOld1, _hBmpOld2 ;

_hDC = GetDC(NULL) ;
if(_hDC)
{
_hDCMem1 = CreateCompatibleDC(_hDC) ;
if(_hDCMem1)
{
_hDCMem2 = CreateCompatibleDC(_hDC) ;
if(_hDCMem2)
{
GetObject(__hHaut,sizeof(BITMAP),&_BmpHaut) ;
GetObject(__hBas,sizeof(BITMAP),&_BmpBas) ;

_hBmpResult = CreateCompatibleBitmap(_hDC,_BmpHaut.bmWidth,2 * _BmpHaut.bmHeight) ;
if(_hBmpResult)
{
_hBmpOld2 = SelectObject(_hDCMem2,_hBmpResult) ;
if(_hBmpOld2)
{
_hBmpOld1 = SelectObject(_hDCMem1,__hHaut) ;
if(_hBmpOld1)
{
SetStretchBltMode(_hDCMem1,COLORONCOLOR) ;
SetStretchBltMode(_hDCMem2,COLORONCOLOR) ;

BitBlt(_hDCMem2,0,0,_BmpHaut.bmWidth,_BmpHaut.bmHeight,_hDCMem1,0,0,SRCCOPY) ;
if(SelectObject(_hDCMem1,__hBas))
{
BitBlt(_hDCMem2,0,_BmpHaut.bmHeight,_BmpBas.bmWidth,_BmpBas.bmHeight,_hDCMem1,0,0,SRCCOPY) ;
SelectObject(_hDCMem1,_hBmpOld1) ;
SelectObject(_hDCMem2,_hBmpOld2) ;
DeleteDC(_hDCMem1) ;
DeleteDC(_hDCMem2) ;
ReleaseDC(NULL,_hDC) ;
return (_hBmpResult) ;
}
else
{
DeleteObject(_hBmpResult) ;
}

SelectObject(_hDCMem1,_hBmpOld1) ;
}
SelectObject(_hDCMem2,_hBmpOld2) ;
}
}
DeleteDC(_hDCMem2) ;
}
DeleteDC(_hDCMem1) ;
}
ReleaseDC(NULL,_hDC) ;
}

return (NULL) ;
}

HBITMAP ImageMergeDroiteGauche(HBITMAP __hGauche,HBITMAP __hDroite)
{
HDC _hDC, _hDCMem1, _hDCMem2 ;
BITMAP _BmpGauche, _BmpDroite ;
HBITMAP _hBmpResult, _hBmpOld1, _hBmpOld2 ;

_hDC = GetDC(NULL) ;
if(_hDC)
{
_hDCMem1 = CreateCompatibleDC(_hDC) ;
if(_hDCMem1)
{
_hDCMem2 = CreateCompatibleDC(_hDC) ;
if(_hDCMem2)
{
GetObject(__hGauche,sizeof(BITMAP),&_BmpGauche) ;
GetObject(__hDroite,sizeof(BITMAP),&_BmpDroite) ;

_hBmpResult = CreateCompatibleBitmap(_hDC,_BmpGauche.bmWidth * 2,_BmpGauche.bmHeight) ;
if(_hBmpResult)
{
_hBmpOld2 = SelectObject(_hDCMem2,_hBmpResult) ;
if(_hBmpOld2)
{
_hBmpOld1 = SelectObject(_hDCMem1,__hGauche) ;
if(_hBmpOld1)
{
SetStretchBltMode(_hDCMem1,COLORONCOLOR) ;
SetStretchBltMode(_hDCMem2,COLORONCOLOR) ;

BitBlt(_hDCMem2,0,0,_BmpGauche.bmWidth,_BmpGauche.bmHeight,_hDCMem1,0,0,SRCCOPY) ;
if(SelectObject(_hDCMem1,__hDroite))
{
BitBlt(_hDCMem2,_BmpGauche.bmWidth,0,_BmpDroite.bmWidth,_BmpDroite.bmHeight,_hDCMem1,0,0,SRCCOPY) ;
SelectObject(_hDCMem1,_hBmpOld1) ;
SelectObject(_hDCMem2,_hBmpOld2) ;
DeleteDC(_hDCMem1) ;
DeleteDC(_hDCMem2) ;
ReleaseDC(NULL,_hDC) ;
return (_hBmpResult) ;
}
else
{
DeleteObject(_hBmpResult) ;
}

SelectObject(_hDCMem1,_hBmpOld1) ;
}
SelectObject(_hDCMem2,_hBmpOld2) ;
}
}
DeleteDC(_hDCMem2) ;
}
DeleteDC(_hDCMem1) ;
}
ReleaseDC(NULL,_hDC) ;
}

return (NULL) ;
}