borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2009 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Creating an installer..)Next Topic (How to handle desktop window for putting non-rectangular objects like MS-Office Assistants in VB6) New Topic New Poll Post Reply
AndreaVB Forum : VB General : How to transparent picture background?
Poster Message
Afshin_Zavar
Level: Professor


Registered: 17-07-2003
Posts: 78

icon How to transparent picture background?

Hi all vb coders!

I'm using a image in pictureBox which it's background color is silver and my form color is yellow
how can transparent image to form color ?

Help me soon please.


____________________________
Persia

30-08-2003 at 11:46 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
yronium
Level: Moderator


Registered: 14-04-2002
Posts: 933
icon Re: How to transparent picture background?

Hello to you.

(I assume that you mean the bitmap background, e. g. if you had a flag picture, the bitmap area external to the flag colours, right?)

It's not a VB question.
You have to edit the bitmap with a photo editor (I use Macromedia Freehand, but you can use any other you like), select the background area with a masking tool, and set it as No Colour.
Then you must save it as a .gif (GIF files support included transparent areas), with a special option. In Freehand this option is named 'Index Transparency', but you can look for Transparent Background, or similar topics, in your favorite editor's help.

It works. I used this method in the last app I've done.
Hope it helps.


____________________________
Real Programmer can count up to 1024 on his fingers

30-08-2003 at 09:04 PM
View Profile Send Email to User Show All Posts | Quote Reply
zak2zak
Level: Guest

icon Re: How to transparent picture background?

May i comment
If U R trying to make transparent imgae background then
Use this API function.
Public Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As Long, _
ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long


SetWindowRgn() Function should be use with a few other
API function to create transparent region on a picture box
or to create shaped form.

The Module .bas code is too long that I would not display it here..

24-09-2003 at 02:17 PM
| Quote Reply
towheedm
Level: Guest

icon Re: How to transparent picture background?

If I understand right, yu would like to make the slver portion of the image transparent.  If so, then you can use the TransparentBlt() function and specify silver as the transparent color.  Remember though, the color that will 'show through' will be the picturebox's background color not the form's background color.

If you want to blend the image with silver then user the AlphaBlend() function

towheedm.

02-12-2003 at 05:10 AM
| Quote Reply
yaardilbar
Level: Guest

icon Re: How to transparent picture background?

try following code:
Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
Private Declare Function CreateBitmap Lib "gdi32" (ByVal nWidth As Long, ByVal nHeight As Long, ByVal nPlanes As Long, ByVal nBitCount As Long, lpBits As Any) As Long
Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare 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 Long
Private Declare Function SetBkColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Type BITMAP '14 bytes
        bmType As Long
        bmWidth As Long
        bmHeight As Long
        bmWidthBytes As Long
        bmPlanes As Integer
        bmBitsPixel As Integer
        bmBits As Long
End Type
Dim WinHnd  As Long

Sub TransparentPaint(objDest As Object, picSource As StdPicture, lngX As Long, lngY As Long, ByVal lngMaskColor As Long)
    Dim lngSrcDC As Long
    Dim lngSaveDC As Long
    Dim lngMaskDc As Long
    Dim lngInvDc As Long
    Dim lngNewPicDc As Long
    
    Dim bmpSource As BITMAP
    
    Dim hResultBmp As Long
    Dim hSaveBmp As Long
    Dim hMaskBmp As Long
    Dim hInvBmp As Long
    
    Dim hSrcPrevBmp As Long
    Dim hSavePrevBmp As Long
    Dim hDestPrevBmp As Long
    Dim hMaskPrevBmp As Long
    Dim hInvPrevBmp As Long
    
    Dim lngOrigScaleMode&
    Dim lngOrigColor&
    '*************************************
    
    '*************************************
    lngOrigScaleMode = objDest.ScaleMode
    lngOrigColor = vbPixels
    '*************************************
    
    '*************************************
    GetObject picSource, Len(bmpSource), bmpSource
    '*************************************
    
    '*************************************
    lngSrcDC = CreateCompatibleDC(objDest.hdc)
    lngSaveDC = CreateCompatibleDC(objDest.hdc)
    lngMaskDc = CreateCompatibleDC(objDest.hdc)
    lngInvDc = CreateCompatibleDC(objDest.hdc)
    lngNewPicDc = CreateCompatibleDC(objDest.hdc)
    '*************************************
    
    '*************************************
    hMaskBmp = CreateBitmap(bmpSource.bmWidth, bmpSource.bmHeight, 1, 1, ByVal 0&)
    hInvBmp = CreateBitmap(bmpSource.bmWidth, bmpSource.bmHeight, 1, 1, ByVal 0&)
    '*************************************
    
    '*************************************
    hResultBmp = CreateCompatibleBitmap(objDest.hdc, bmpSource.bmWidth, bmpSource.bmHeight)
    hSaveBmp = CreateCompatibleBitmap(objDest.hdc, bmpSource.bmWidth, bmpSource.bmHeight)
    '*************************************
    
    '*************************************
    hSrcPrevBmp = SelectObject(lngSrcDC, picSource)
    hSavePrevBmp = SelectObject(lngSaveDC, hSaveBmp)
    hMaskPrevBmp = SelectObject(lngMaskDc, hMaskBmp)
    hInvPrevBmp = SelectObject(lngInvDc, hInvBmp)
    hDestPrevBmp = SelectObject(lngNewPicDc, hResultBmp)
    '*************************************
    
    '*************************************
    BitBlt lngSaveDC, 0, 0, bmpSource.bmWidth, bmpSource.bmHeight, lngSrcDC, 0, 0, vbSrcCopy
    '*************************************
    
    '*************************************
    lngOrigColor = SetBkColor(lngSrcDC, lngMaskColor)
    BitBlt lngMaskDc, 0, 0, bmpSource.bmWidth, bmpSource.bmHeight, lngSrcDC, 0, 0, vbSrcCopy
    '*************************************
    
    '*************************************
    SetBkColor lngSrcDC, lngOrigColor
    '*************************************
    
    '*************************************
    BitBlt lngInvDc, 0, 0, bmpSource.bmWidth, bmpSource.bmHeight, lngMaskDc, 0, 0, vbNotSrcCopy
    '*************************************
    
    '*************************************
    BitBlt lngNewPicDc, 0, 0, bmpSource.bmWidth, bmpSource.bmHeight, objDest.hdc, lngX, lngX, vbSrcCopy
    '*************************************
    
    '*************************************
    BitBlt lngNewPicDc, 0, 0, bmpSource.bmWidth, bmpSource.bmHeight, lngMaskDc, 0, 0, vbSrcAnd
    '*************************************
    
    '*************************************
    BitBlt lngSrcDC, 0, 0, bmpSource.bmWidth, bmpSource.bmHeight, lngInvDc, 0, 0, vbSrcAnd
    '*************************************
    
    '*************************************
    BitBlt lngNewPicDc, 0, 0, bmpSource.bmWidth, bmpSource.bmHeight, lngSrcDC, 0, 0, vbSrcPaint
    '*************************************
    
    '*************************************
    BitBlt objDest.hdc, lngX, lngY, bmpSource.bmWidth, bmpSource.bmHeight, lngNewPicDc, 0, 0, vbSrcCopy
    '*************************************
    
    '*************************************
    BitBlt lngSrcDC, 0, 0, bmpSource.bmWidth, bmpSource.bmHeight, lngSaveDC, 0, 0, vbSrcCopy
    '*************************************
    
    '*************************************
    SelectObject lngSrcDC, hSrcPrevBmp
    SelectObject lngSaveDC, hSavePrevBmp
    SelectObject lngNewPicDc, hDestPrevBmp
    SelectObject lngMaskDc, hMaskPrevBmp
    SelectObject lngInvDc, hInvPrevBmp
    '*************************************
    
    '*************************************
    DeleteObject hSaveBmp
    DeleteObject hMaskBmp
    DeleteObject hInvBmp
    DeleteObject hResultBmp
    DeleteDC lngSrcDC
    DeleteDC lngSaveDC
    DeleteDC lngInvDc
    DeleteDC lngMaskDc
    DeleteDC lngNewPicDc
    '*************************************
    
    '*************************************
    objDest.ScaleMode = lngOrigScaleMode
End Sub
Private Sub Command1_Click()
'    Load Form2
'    Form2.Show '
    WinHnd = GetDesktopWindow()
    WinHnd = GetDC(WinHnd)
    TransparentPaint WinHnd, LoadPicture("Qalandar on Desktop.bmp"), 0, 0, QBColor(15)
    
    
    
    
End Sub

30-05-2004 at 09:54 PM
| Quote Reply
saladirs
Level: Guest

icon Re: How to transparent picture background?

WinHnd as Long or Object

31-05-2004 at 09:18 AM
| Quote Reply
AndreaVB Forum : VB General : How to transparent picture background?
Previous Topic (Creating an installer..)Next Topic (How to handle desktop window for putting non-rectangular objects like MS-Office Assistants in VB6) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2009 Andrea Tincaniborder