Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools


If you ever need to create transparent BMP then don't worry here is an API which makes your life easy. To make this demo simple I have avoided color selection. In this demo default transparent color is first left top pixel color of source image.

Step-By-Step Example

- Create a standard exe project
- Add 2 picturebox and 3 command button controls on the form1
- Assign Picture to Picture1
- Add the following code in form1

Click here to copy the following block
Private Declare Function TransparentBlt Lib "msimg32" _
    (ByVal hdcDest As Long, _
    ByVal nXOriginDest As Long, _
    ByVal nYOriginDest As Long, _
    ByVal nWidthDest As Long, _
    ByVal nHeightDest As Long, _
    ByVal hdcSrc As Long, _
    ByVal nXOriginSrc As Long, _
    ByVal nYOriginSrc As Long, _
    ByVal nWidthSrc As Long, _
    ByVal nHeightSrc As Long, _
    ByVal crTransparent As Long) _
    As Long

Private Declare Function GetPixel Lib "gdi32" _
    (ByVal hdc As Long, _
    ByVal x As Long, _
    ByVal y As Long) _
    As Long

Private Function MakeTransparentRegion(pbSource As PictureBox, _
                    pbDestination As PictureBox)
  Dim lTransColor As Long

  '//By default take first left-top pixel as transparent color
  lTransColor = GetPixel(pbSource.hdc, 0, 0)

  Call TransparentBlt(pbDestination.hdc, 0, 0, pbSource.ScaleWidth, _
      pbSource.ScaleHeight, _
      pbSource.hdc, 0, 0, _
      pbSource.ScaleWidth, _
      pbSource.ScaleHeight, _
      lTransColor)
  Picture2.Refresh
End Function

Private Sub Command1_Click()
  MakeTransparentRegion Picture1, Picture2
End Sub

Private Sub Command2_Click()
  Unload Me
End Sub

Private Sub Command3_Click()
  Picture2.Cls
End Sub

Private Sub Form_Load()
  'Picture1.Picture = LoadPicture(App.Path & "\test.bmp")
  Command1.Caption = "Start"
  Command2.Caption = "Exit"
  Command3.Caption = "Clear"

  With Picture1
    .AutoRedraw = True
    .ScaleMode = 3
    With Picture2
      .AutoRedraw = True
      .ScaleMode = 3
      .Width = Picture1.Width
      .Height = Picture1.Height
    End With
  End With
End Sub


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.