Transparent bitmap

zhaozj2021-02-16  55

'The following in Form needs two Picturebox, an Image Control, a Command Box

Vate Sub Command1_Click () DIM DX AS Long, DY As Long

Call GetinvertmaskPic (Picture1, Image1, RGB (255, 255)) 'Note: Please confirm what is the background color of the Pen.BMP map, this example is white, so use RGB (255, 255, 255) Call getmaskpic (Picture1, Image1 RGB (255, 255, 255)))

DX = me.scalex (image1.picture.width, vbhimetric, vbpixels) DY = me.scaley (image1.picture.height, vbhimetric, vbpixels)

'Note: The following will remove the image of Image1 in Picture2 set pictures. DX, DY, HINVERTMASKDC, 0, 0, VBSRCandbitblt Picture2.hdc, 0, 0, DX, DY, Picture1.hdc, 0, 0, VBSRCPAINT

End Sub

Private Sub Form_Load () Picture1.Visible = FalsePicture1.AutoRedraw = True 'NOTE: Picture1.Appearance = 0 NOTE: To set in advance Picture1.BorderStyle = 0Set Image1.Picture = LoadPicture ( "c: /1.wmf")' Notes : Please set your chart 'Set Picture2.Picture = LoadPicture ("C: /2.BMP")' Note: Set to your own background diagram Picture2.Height = Image1.HeightPictPictTure2.Width = Image1.widthPicture2. Picture = image1.picturend sub

'' Module1 ---------------------------

Declare Function CreateCompatibleBitmap Lib "GDI32" _ (ByVal hDc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As LongDeclare Function CreateCompatibleDC Lib "GDI32" _ (ByVal hDc As Long) As LongDeclare Function DeleteObject Lib "GDI32" _ (ByVal hObject As Long) As LongDeclare Function SelectObject Lib "GDI32" _ (ByVal hDc As Long, ByVal hObject As Long) As LongDeclare Function DeleteDC Lib "GDI32" _ (ByVal hDc As Long) As LongDeclare Function BitBlt Lib "GDI32" _ (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, _ ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, _ ByVal xSrc As Long, ByVal YSrc As Long, ByVal dwRop As Long) As LongDeclare Function SetBkColor LIB "GDI32" _ (Byval HDC As Long, BYVAL CRCOLOR As Long) As longpublic hmaskdc As long, HBMPMASK AS Longpublic Hinvertmaskdc As Long, HBmpinvertmask As Long

'Note: The hMASKDC's self-order function, the image in this hmaskdc is the background of the Souimg diagram for white' Note: The foreground map of Souimg is black 'Note: Picback: Picture boxes used to make Mask map' Note: Souimg: Place the image of the image of the original image, can be image / picturebox 'Note: TColor 叁: Color of Want to remove, Souimg Background Color Public Sub getMaskPic (Picback As Picturebox, _ Souimg As Control, ByVal Tcolor AS Long) Dim HDCMONO, HBMPMONO, HBMPOLDDIM Colorback As Longdim DX As long, DY As Long

WITH PICBACK 'Note: Number of this map, by Pixels Dx = .scalex (Souimg.Picture.Width, Vbhimetric, VBPixels) DY = .scaley (Souimg.Picture.Height, Vbhimetric, VBPixels)' Note: Set PictureBox Source Image size is the same size .Width = souImg.Width .Height = souImg.Height Set .Picture = souImg.Picture End with hdcMono = CreateCompatibleDC (0) hbmpMono = CreateCompatibleBitmap (hdcMono, dx, dy) hbmpOld = SelectObject (hdcMono, HBMPMONO) Picback.Autoredraw = true picback.backcolor = RGB (255, 255, 255) Colorback = setbkcolor (picback.hdc, tcolor) Bitblt HDCMONO, 0, 0, DX, DY, Picback.hdc, 0, 0, VBSRCCPY CALL SetBkColor (picBack.hDc, ColorBack) BitBlt picBack.hDc, 0, 0, dx, dy, hdcMono, 0, 0, vbSrcCopy hMaskDC = CreateCompatibleDC (0) hBmpMask = CreateCompatibleBitmap (picBack.hDc, dx, dy) Call SelectObject (hMaskDC , hbmpmask Bitblt Hmaskdc, 0, 0, DX, DY, Picback.hdc, 0, 0, VBsrccopy Call SelectObject (HDCMONO, HBMPOLD) CALLETED (HDCMON) CALL DeleteObject (HBMPMONO) End Sub 'Note: The hinvertmaskdc's self-order function, the image in this hmaskdc is the background of the Souimg chart is white' Note: The foreground map of Souimg is black 'Note: Picback number: used to make Mask Picture box 'Number: Souimg Number: Place the image of the image of the image, can be image / picturebox' Note: TCOLOR: Color of Want to remove, the background color of Souimg Public Sub getinvertmaskpic (Picback As Picturebox, _ Souimg As Control, Byval Tcolor As Long Dim HDCMONO, HBMPMONO, HBMPOLDDIM Colorback As Longdim Dx As Single, DY As Single

With picBack dx = .ScaleX (souImg.Picture.Width, vbHimetric, vbPixels) dy = .ScaleY (souImg.Picture.Height, vbHimetric, vbPixels) 'Note: Source Image size as the set of same .Width = souImg pictureBox .Width .Height = souImg.Height Set .Picture = souImg.Picture End With hdcMono = CreateCompatibleDC (0) hbmpMono = CreateCompatibleBitmap (hdcMono, dx, dy) hbmpOld = SelectObject (hdcMono, hbmpMono) picBack.AutoRedraw = True picBack.BackColor = RGB (255, 255, 255) Colorback = setbkcolor (Picback.hdc, Tcolor) Bitblt HDCMONO, 0, 0, DX, DY, Picback.hdc, 0, 0, VBSRCCPY CALL SetBKCOLOR (Picback.hdc, Colorback) Bitblt Picback. hDc, 0, 0, dx, dy, hdcMono, 0, 0, vbNotSrcCopy hInvertMaskDC = CreateCompatibleDC (0) hBmpInvertMask = CreateCompatibleBitmap (picBack.hDc, dx, dy) Call SelectObject (hInvertMaskDC, hBmpInvertMask) BitBlt hInvertMaskDC, 0, 0, dx , Dy, Picback.hdc, 0, 0, VBSRCCOPYCALL SELECTOBJECT (HDCMONO, HBMPOLD) CALLETEDC (HDCMON) CA LL DeleteObject (HBMPMONO) End Sub

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

New Post(0)