请问怎样去除游戏“精灵”的背景色,当然是不用另加掩图,因为另加掩图太麻烦,每次变换图片都要另找一幅掩图,请问怎样可以指定背景色就可去除。(Win98,VB6.0)   

解决方案 »

  1.   

    只有另加掩图,很遗憾......
    当然,如果你是用DirectX实现的DirectDraw有它的去背景方法你不必担心。
    你可以参阅:
    http://www.csdn.net/cnshare/soft/12/12207.shtm
    http://www.csdn.net/cnshare/soft/12/12208.shtm
    用BitBlt加掩图实现的Super Mario和Tankwar。
    --------------------------------------------------------------------
    Made by Thirdapple's Studio(http://3rdapple.51.net/)
      

  2.   

    http://www.csdn.net/expert/topic/945/945587.xml?temp=.8969995
      

  3.   

    'Déclaration des constantes
    Public Const SRCCOPY = &HCC0020
    Public Const SRCINVERT = &H660046
    Public Const SRCAND = &H8800C6'Déclaration des fonctions
    Declare Function SetBkColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long
    Declare Function GetBkColor Lib "gdi32" (ByVal hdc As Long) As Long
    Declare Function GetTextColor Lib "gdi32" (ByVal hdc As Long) As Long
    Declare Function SetTextColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long
    Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
    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
    Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
    Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
    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
    Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As LongPublic Function TransBitBlt(ByVal hDCD As Long, ByVal x As Long, ByVal y As Long, ByVal DX As Long, ByVal DY As Long, ByVal hDCS As Long, ByVal X0 As Long, ByVal Y0 As Long, ByVal TransColor As Long) As Boolean
    Dim RGBBK As Long
    Dim RetL As Long
    Dim RetI As Long
    Dim RGBBKS As Long
    Dim RGBFG As Long
    Dim HbmMask As Long
    Dim HbmT As Long
    Dim hDCMask As Long
    Dim F As Boolean
    F = FalseRetL = SetBkColor(hDCD, TransColor)RGBBK = GetBkColor(hDCD)
    RGBFG = GetTextColor(hDCD)
    RGBBKS = GetBkColor(hDCS)RetL = SetTextColor(hDCD, RGB(0, 0, 0))hDCMask = CreateCompatibleDC(hDCS)If IsNull(hDCMask) Then
    TransBitBlt = F
    Exit FunctionEnd If
    HbmMask = CreateBitmap(DX, DY, 1, 1, ByVal 0&)If IsNull(HbmMask) Then
    RetI = DeleteDC(hDCMask)
    TransBitBlt = F
    Exit FunctionEnd If
    HbmT = SelectObject(hDCMask, HbmMask)RetL = SetBkColor(hDCS, RGBBK)RetI = BitBlt(hDCMask, 0, 0, DX, DY, hDCS, X0, Y0, SRCCOPY)RetL = SetBkColor(hDCD, RGB(255, 255, 255))RetI = BitBlt(hDCD, x, y, DX, DY, hDCS, X0, Y0, SRCINVERT)
    RetI = BitBlt(hDCD, x, y, DX, DY, hDCMask, 0, 0, SRCAND)
    RetI = BitBlt(hDCD, x, y, DX, DY, hDCS, X0, Y0, SRCINVERT)F = TrueRetI = SelectObject(hDCMask, HbmT)RetI = DeleteObject(HbmMask)RetI = DeleteDC(hDCMask)RetL = SetBkColor(hDCD, RGBBK)
    RetL = SetTextColor(hDCD, RGBFG)
    RetL = SetBkColor(hDCS, RGBBKS)TransBitBlt = F
    End Function