Transfer irregular bitmap with Mask method

zhaozj2021-02-16  51

#define fore_rop3 (ROP4) (0x00FFFFF & (ROP4)))

#define back_rop3 (ROP3FROMINDEX (swaprop3_srcdst (Byte ((ROP4 >> 24)))))))))))))

#define dstcopy 0x00aa0029

#define dsterase 0x00220326 // DEST = DEST & (~ SRC): DSNA

Bool WinApi Mymaskblt (HDC HDCDEST, INT NXDEST, INT NYDEST, INT NWIDTH, INT NHEIGHT,

HDC HDCSRC, INT NXSRC, INT NYSRC,

Hbitmap HBmmask, Int Xmask, Int Ymask,

DWORD DWROP

)

{

IF (hbmmask == null)

Return Bitblt (HDCDEST, NXDEST, NYDEST, NWIDTH, NHEIGHT, HDCSRC,

NXSRC, NYSRC, Fore_ROP3 (DWROP));

/ / 1. make Mask Bitmap's DC

HDC hdcmask = :: createcompatibledc (hdcdest);

Hbitmap Holdmaskbitmap = (Hbitmap) :: SelectObject (HDCMask, HBmmask);

ASSERT (Holdmaskbitmap);

// 2. make masked background bitmap

// 2.1 make bitmap

HDC HDC1 = :: CreateCompatibleDC (HDCDEST);

Assert (HDC1);

Hbitmap hbitmap2 = :: createcompatiblebitmap (HDCDest, NWIDTH, NHEIGHT);

Hbitmap Holdbitmap2 = (Hbitmap) :: SelectObject (HDC1, HBitmap2);

Assert (HoldbitMap2);

// 2.2 Draw Dest BitMap and Mask

DWORD DWROP3 = back_rop3 (dwrop);

:: Bitblt (HDC1, 0, 0, NWIDTH, NHEIGHT, HDCSRC, NXSRC, NYSRC, SRCCOPY);

:: Bitblt (HDC1, 0, 0, NWIDTH, NHEIGHT, HDCDEST, NXDEST, NYDEST, DWROP3);

:: Bitblt (HDC1, 0, 0, NWIDTH, NHEIGHT, HDCMASK, Xmask, Ymask, DSterase);

// 3. make masked foreground bitmap

// 3.1 make bitmap

HDC HDC2 = :: CreateCompatibleDC (HDCDEST);

ASSERT (HDC2);

Hbitmap hbitmap3 = :: createcompatiblebitmap (hdcdest, nwidth, nheight);

Hbitmap Holdbitmap3 = (Hbitmap) :: SelectObject (HDC2, HBitmap3);

Assert (Holdbitmap3);

// 3.2 Draw src Bitmap and mask

DWrop3 = fore_rop3 (dwrop);

:: Bitblt (HDC2, 0, 0, NWIDTH, NHEIGHT, HDCDEST, NXDEST, NYDEST, SRCCOPY);

:: Bitblt (HDC2, 0, 0, NWIDTH, NHEIGHT, HDCSRC, NXSRC, NYSRC, DWROP3);

:: Bitblt (HDC2, 0, 0, NWIDTH, NHEIGHT, HDCMASK, Xmask, Ymask, srcand);

// 4. Combine Two Bitmap and Copy It to HDCDEST

:: Bitblt (HDC1, 0, 0, NWIDTH, NHEIGHT, HDC2, 0, 0, SrcPaint);

:: Bitblt (HDCDest, NXDest, NYDEST, NWIDTH, NHEIGHT, HDC1, 0, 0, SRCCOPY);

// 5. Restore All Object

:: SelectObject (HDCmask, Holdmaskbitmap);

:: SelectObject (HDC1, Holdbitmap2);

:: SelectObject (HDC2, Holdbitmap3);

// 6. Delete All Temp Object

DeleteObject (hbitmap2);

DeleteObject (HbitMap3);

Deletedc (HDC1);

Deletedc (HDC2);

Deletedc (HDCMask);

Return True;

}

转载请注明原文地址:https://www.9cbs.com/read-24788.html

New Post(0)