Talking about how to use PB to implement pictures transparent superposition (adapted)

zhaozj2021-02-16  55

Author: BALLOONMAN2002 2004 Nian 6 Yue 26 Ri

This article intends to combine the PowerBuilder language, briefly describe how to implement pictures transparent superimposed effects, this example is referred to and has adapted a VB article for previous streaming. Since the time is too long, the source has not been found, here, to the original author. See the program effect picture:

http://blog.9cbs.net/images/blog_9cbs_net/balloonman2002/17312/r_pic_overlap.jpg

First, basic ideas

The principle of the program is to create two template DCs for the shielding effect (load monochrome mask bitmap, and both of these is just the opposite relationship, through NotSrcCopy), respectively with source DC and target DC (SRCAND), at this time, the area of ​​the source DC and the transparent DC and the not transparent area are directly divided into a black portion (ie, the pixel color is 0) (specifically the transparent area in the source DC is black, the target Do not transparent zone in the DC as black), and finally "Operation" source DC and target DC will be "different or" SrcXor) operations to implement the transparent superposition of both. The key to this is to use 0 and no matter what the other value (0, 1) is still original (ie, still 0, 1), so that the result of the final xor of pixels can be guaranteed. The superimposed effect is retained. Similar to the results of we can also "with any of the other values" and "are still the same effect.

This is the key to create the mask DC, which is created with CreateBitmap, SetBkColor, Bitblt. See the following code as follows.

Second, the specific implementation

(1) Basic work

Create a Window window and three Picture controls, which are used for display source pictures, target pictures, synthetic results pictures.

Disclaimer local external functions:

Function Ulong CreateCompatibleDC (Ulong HDC) Library "GDi32.dll"

Function Ulong CreateBitmap (Ulong Nwidth, Ulong NHEIGHT, ULONG NPLANES, ULONG NBITCOUNT, ULONG LPBITS) Library "gdi32.dll"

Function Ulong CreateCompabilityBitmap (Ulong HDC, Ulong Nwidth, Ulong NHEight) library "gdi32.dll"

Function Ulong SelectObject (Ulong HDC, Ulong Hobject) library "gdi32.dll"

Function Ulong SetBkcolor (Ulong HDC, Ulong Crcolor) library "gdi32.dll"

Function Ulong Bitblt (Ulong HDestdc, Ulong X, Ulong Y, Ulong Nwidth, Ulong NHEIGHT, ULONG HSRCDC, ULONG XSRC, ULONG YSRC, ULONG DWROP) Library "gdi32.dll"

Function Ulong DeleteObject (Ulong Hobject) library "gdi32.dll"

Function Ulong Deletedc (Ulong HDC) Library "GDI32.DLL"

Function Ulong Getdc (Ulong Hwnd) Library "User32.dll"

Function ulong ReleaseDC (ulong hwnd, ulong hdc) LIBRARY "user32.dll" Function ulong LoadImage (ulong hInst, ref string lpsz, ulong un1, ulong n1, ulong n2, ulong un2) LIBRARY "user32.dll" ALIAS FOR "LoadImageA"

(2) Specific code

Long Origcolor

Long Origmode

Long Savedc

Long Maskdc

Long invdc

Long Resultdc

Long hsavebmp

Long hmaskbmp

Long hinvbmp

Long HRESULTBMP

Long hsaveprevbmp

Long hmaskprevbmp

Long hinvprevbmp

Long HDestPrevbmp

Long hsrcdc

Long HDestDC

Long Nwidth, NHEIGHT

Long Transch

Long Ret, Hbitmap

String ls_tmp

HSRCDC = CREATECOMPATIBLEDC (GetDC (Handle (p_1))))

HDestDC = Getdc (Handle (p_3))

NWIDTH = UnitStopixels (p_1.width, xunitstopixels!)

NHEIGHT = UnitStopixels (p_1.height, yunitstopixels!)

// Here, the PB Unit unit is used by default, and the API processing metrics use pixel units therefore need to perform unit conversion.

TRANSCOLOR = 0

// Set the RGB color to be transparent here, here is black;

Ls_tmp = "srce.bmp"

Hbitmap = loading (0, LS_TMP, 0, 0, 0, 0)

Savedc = CreateCompatibleDC (HDestDC)

Maskdc = CreateCompatibleDC (HDestDC)

INVDC = CREATECOMPALEDC (HDestDC)

Resultdc = CreateCompAMPATIBLEDC (HDestDC)

Hmaskbmp = CreateBitmap (NWidth, NHEIGHT, 1, 1, 0)

Hinvbmp = CreateBitmap (NWIDTH, NHEIGHT, 1, 1, 0)

HRESULTBMP = CREATECOMPATIBLEBITMAP (HDESTDC, NWIDTH, NHEIGHT)

HsaveBMP = CreateCompATIBLEBITMAP (HDestDC, NWIDTH, NHEIGHT)

RET = SELECTOBJECT (HSRCDC, HBitmap)

HSAVEPREVBMP = SELECTOBJECT (Savedc, HsaveBMP)

HMASKPREVBMP = SELECTOBJECT (Maskdc, HmaskBMP)

Hinvprevbmp = selectObject (Invdc, Hinvbmp)

HDestPrevbmp = SelectObject (Resultdc, HRESULTBMP)

Origcolor = setbkcolor (hsrcdc, transcolor)

RET = Bitblt (Maskdc, 0, 0, NWidth, NHEight, HSRCDC, 0, 0, 13369376)

// Note: 13369376 is the parameter of the Bitblt function - Srccopy, indicating that directly copying the source rectangular area Transcolor = setBkcolor (HSRCDC, OrigColor)

Ret = Bitblt (INVDC, 0, 0, NWIDTH, NHEIGHT, MASKDC, 0, 0, 3342344)

// Note: 3342244 The parameters of the Bitblt function - NOTSRCCCOPY indicates that the color rectangular area is reversed to the target rectangular area

Ret = Bitblt (Resultdc, 0, 0, NWIDTH, NHEIGHT, HDESTDC, 0, 0, 13369376)

Ret = Bitblt (Resultdc, 0, 0, NWIDTH, NHEIGHT, MASKDC, 0, 0, 8913094)

// Note: 8913094 is the parameter of the Bitblt function, indicating the merger of the source and target rectangular area by using the AND (with) operator.

Ret = Bitblt (Savedc, 0, 0, NWidth, NHEight, HSRCDC, 0, 0, 13369376)

Ret = Bitblt (Savedc, 0, 0, NWIDTH, NHEIGHT, INVDC, 0, 0, 8913094)

Ret = Bitblt (Resultdc, 0, 0, NWIDTH, NHEIGHT, Savedc, 0, 0, 6684742)

/ Note: 6684742 The parameters of the Bitblt function -srcinvert, indicating the color of the source and the target rectangular area by using the Boolean xor (videol) operator

Ret = Bitblt (HDestDC, 0, 0, NWIDTH, NHEIGHT, RESULTDC, 0, 0, 13369376)

RET = SELECTOBJECT (Savedc, HsavePrevbmp)

RET = SELECTOBJECT (Resultdc, HDestPrevbmp)

Ret = selectObject (Maskdc, HmaskPrevbmp)

RET = SELECTOBJECT (Invdc, HinvpRevbmp)

Ret = deleteObject (hsavebmp)

Ret = deleteObject (hmaskbmp)

Ret = deleteObject (Hinvbmp)

Ret = deleteObject (HRESULTBMP)

Ret = deletedc (savedc)

Ret = deletedc (invdc)

Ret = deletedc (Maskdc)

Ret = deletedc (resultDC)

Ret = releasedc (Handle (p_1), hsrcdc)

Ret = releasedc (Handle (p_3), hdestdc)

At this point, the picture transparent superposition effect is complete, the renderings are shown in:

http://blog.9cbs.net/images/blog_9cbs_net/balloonman2002/17312/r_pic_overlap.jpg

For further information, please contact QQ: 27855043, MSN: weiyin2001@msn.com

If you have something wrong, you respect your guidance.

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

New Post(0)