[API]
BITMAPINFOHEADER
RtlMoveMemory
GetDC
CreateCompatibleBitmap
ReleaseDC
SetDIBits
DeleteDC

[CODE]
Public Function RawBitmapToBitmapTransparent(ByVal xData As String, ByVal TransparentBackIndex As Long, ByVal TransparentBackColor As Long) As Long
  Dim xType1 As BITMAPINFOHEADER
  Dim xChar1 As String
  Dim hDC As Long
  Dim hBmp As Long

  ' Strip any bitmap file header
  If Len(xData) > 3& Then
    Call RtlMoveMemory(ByVal VarPtr(hDC), ByVal xData, 4&)
    If (hDC And &HFFFF&) = &H4D42 Then
      xData = Mid(xData, 15&)
      End If
    End If
  If Len(xData) > 40& Then
    Call RtlMoveMemory(xType1, ByVal xData, 40&)
    Select Case xType1.biBitCount
      Case 8&: xChar1 = Mid(xData, 1065&): xData = Left(xData, 1064&) ' 40 + 4*256 indexes
      Case 4&: xChar1 = Mid(xData, 105&): xData = Left(xData, 104&) ' 40 + 4*16 indexes
      Case 1&: xChar1 = Mid(xData, 49&): xData = Left(xData, 48&) ' 40 + 4*x indexes
      End Select
    If Not Len(xChar1) = 0& Then
      If Not xType1.biBitCount = 24& Then
        'a=1:? 40+(2^a)*4
        If TransparentBackIndex < 0& Then TransparentBackIndex = 2 ^ xType1.biBitCount + TransparentBackIndex
        If Not (TransparentBackColor < 0& Or TransparentBackIndex < 0&) And TransparentBackColor < &H1000000 And TransparentBackIndex < 2 ^ xType1.biBitCount Then
          Mid(xData, 41& + TransparentBackIndex * 4&, 4&) = Chr(TransparentBackColor \ &H10000) & Chr((TransparentBackColor And &HFF00&) \ &H100&) & Chr(TransparentBackColor And &HFF&) & vbNullChar
          End If
        End If
      hDC = GetDC(0&)
      If Not hDC = 0& Then
        hBmp = CreateCompatibleBitmap(hDC, xType1.biWidth, xType1.biHeight)
        Call ReleaseDC(0&, hDC)
        If Not hBmp = 0& Then
          hDC = CreateCompatibleDC(0&)
          If Not hDC = 0& Then
            If SetDIBits(hDC, hBmp, 0&, xType1.biHeight, ByVal xChar1, ByVal xData, 0&) Then
              RawBitmapToBitmapTransparent = hBmp
              End If
            Call DeleteDC(hDC)
            End If
          If RawBitmapToBitmapTransparent = 0& Then
            Call DeleteObject(hBmp)
            End If
          End If
        End If
      End If
    End If
  End Function