如果不是透明的Gif或ico
用Image控件无法透明去学 绘图API、计算机图形学、DIB位图处理

解决方案 »

  1.   

    http://www.dapha.net/vb/list.asp?id=17 
    上有/
      

  2.   

    'This project requires two picture boxes
    'Both picture boxes should contain a picture
    Const AC_SRC_OVER = &H00
    Private Type BLENDFUNCTION
      BlendOp As Byte
      BlendFlags As Byte
      SourceConstantAlpha As Byte
      AlphaFormat As Byte
    End Type
    Private Declare Function AlphaBlend Lib "msimg32.dll" (ByVal hdc As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal hdc As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal BLENDFUNCT As Long) As Long
    Private Declare Sub RtlMoveMemory Lib "kernel32.dll" (Destination As Any, Source As Any, ByVal Length As Long)
    Private Sub Form_Load()
        'KPD-Team 2000
        'URL: http://www.allapi.net/
        'E-Mail: [email protected]
        Dim BF As BLENDFUNCTION, lBF As Long
        'Set the graphics mode to persistent
        Picture1.AutoRedraw = True
        Picture2.AutoRedraw = True
        'API uses pixels
        Picture1.ScaleMode = vbPixels
        Picture2.ScaleMode = vbPixels
        'set the parameters
        With BF
            .BlendOp = AC_SRC_OVER
            .BlendFlags = 0
            .SourceConstantAlpha = 128
            .AlphaFormat = 0
        End With
        'copy the BLENDFUNCTION-structure to a Long
        RtlMoveMemory lBF, BF, 4
        'AlphaBlend the picture from Picture1 over the picture of Picture2
        AlphaBlend Picture2.hdc, 0, 0, Picture2.ScaleWidth, Picture2.ScaleHeight, Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, lBF
    End Sub
      

  3.   

    http://www.dapha.net/vb/list.asp?id=16
      

  4.   

    我记得有createcomptibleDC ,和bitblt 也可实现。
      

  5.   

    AlphaBlend只能实现半透明
    应该用TransparentBlt
    Private Declare Function TransparentBlt Lib "msimg32.dll" (ByVal hdc 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 nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal crTransparent As Long) As Boolean
      

  6.   

    Public Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
    Public Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
    Public Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
    Public Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
    Public Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
    Dim CurRgn, TempRgn As Long  ' Region variablesPublic Function AutoFormShape(bg As Form, transColor)
        Dim X, Y As Integer
        CurRgn = CreateRectRgn(0, 0, bg.ScaleWidth, bg.ScaleHeight)  ' Create base region which is the current whole window    While Y <= bg.ScaleHeight / 15 ' Go through each column of pixels on form
            While X <= bg.ScaleWidth / 15 ' Go through each line of pixels on form
                If GetPixel(bg.hdc, X, Y) = transColor Then  ' If the pixels color is the transparency color (bright purple is a good one to use)
                    TempRgn = CreateRectRgn(X, Y, X + 1, Y + 1)  ' Create a temporary pixel region for this pixel
                    success = CombineRgn(CurRgn, CurRgn, TempRgn, RGN_DIFF)  ' Combine temp pixel region with base region using RGN_DIFF to extract the pixel and make it transparent
                    DeleteObject (TempRgn)  ' Delete the temporary pixel region and clear up very important resources
                End If
                X = X + 1
            Wend
                Y = Y + 1
                X = 0
        Wend
        success = SetWindowRgn(bg.hWnd, CurRgn, True)  ' Finally set the windows region to the final product
        DeleteObject (CurRgn)  ' Delete the now un-needed base region and free resources
    End Function
      

  7.   

    你需要创建掩码分别同bitmap图片和背景图片进行逻辑与操作,再将处理过的bitmap图片和背景图片进行异或操作,就能达到使bitmap图片的背景区域透明的显示背景图片的内容的效果
    详细信息请参考:
    Q94961 How to Create a Transparent Bitmap Using Visual Basic
    http://support.microsoft.com/support/kb/articles/q94/9/61.asp
      

  8.   

    在 http://www.r4cn.com 上有个标准模块下载。主要方法是将一个图片需要透明的部分设置成一种颜色(Mask color,例如紫色)然后就可以用那个标准模块的 TranslateColor 函数将这个图片绘制在其他的图片之上了。