[API]
BITMAPINFOHEADER
RtlMoveMemory
GetDC
CreateCompatibleBitmap
ReleaseDC
SetDIBits
DeleteDC

[CODE]
Public Function RawBitmapToBitmap(ByVal xData As String) 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(xLong1), ByVal xData, 4&)
    If (xLong1 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
      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
              RawBitmapToBitmap = hBmp
              End If
            Call DeleteDC(hDC)
            End If
          If RawBitmapToBitmap = 0& Then
            Call DeleteObject(hBmp)
            End If
          End If
        End If
      End If
    End If
  End Function
