Io ho un'altra versione della funzione.
Prova a sostituirla. Ma non sono sicuro che funzioni.
codice:
Public Function LeggeBMP(FileName As String, _
ByRef ImgBuf() As Byte, _
ByRef ImgColor() As Byte, _
ByRef ImgWidth As Long, _
ByRef ImgHeight As Long, _
ByRef ImgBPP As Byte, _
Optional ColorSpace As pdfColorSpace = pdfRGB) As Boolean
Dim C As Long
Dim fb As Integer
Dim BMPH As BITMAPFILEHEADER_Type
Dim BMPI As BITMAPINFO_Type
Dim XBMP As Long
Dim BPP As Byte
Dim i As Long
Dim kk As Long
Dim blnFlag As Boolean
Dim tempBuf() As Byte
Dim tempCol() As RGBQUAD_Type
Dim lngGray As Long
fb = FreeFile
Open FileName For Binary As #fb
'
Get #fb, , BMPH
Get #fb, , BMPI.BMPH
LeggeBMP = False
If BMPH.bfType = "BM" Then
BPP = BMPI.BMPH.biBitCount
If BPP <= 8 Then
' legge la palette di colori
ReDim tempCol(0 To (2 ^ BPP) - 1)
Get #fb, , tempCol()
If ColorSpace = pdfRGB Then
ReDim ImgColor(1 To 3 * (2 ^ BPP))
For C = 0 To (2 ^ BPP) - 1
ImgColor(C * 3 + 1) = tempCol(C).Red
ImgColor(C * 3 + 2) = tempCol(C).Green
ImgColor(C * 3 + 3) = tempCol(C).Blue
Next C
Else
ReDim ImgColor(1 To (2 ^ BPP))
For C = 0 To (2 ^ BPP) - 1
lngGray = (0.33 * tempCol(C).Red + 0.59 * tempCol(C).Green + 0.11 * tempCol(C).Blue)
ImgColor(C + 1) = IIf(lngGray > 255, 255, lngGray)
Next C
End If
End If
XBMP = ((BMPI.BMPH.biWidth * BPP / 8) + 3&) And &HFFFFFFFC ' [Bytes].
ImgWidth = BMPI.BMPH.biWidth
ImgHeight = BMPI.BMPH.biHeight
ImgBPP = BMPI.BMPH.biBitCount
ReDim tempBuf(1 To BMPI.BMPH.biHeight * XBMP)
Get #fb, BMPH.bfOffBits + 1, tempBuf()
Close #fb
ReDim ImgBuf(1 To BMPI.BMPH.biHeight * XBMP)
kk = 0
If BPP > 8 Then
blnFlag = ((BMPI.BMPH.biWidth Mod 4) <> 0)
If ColorSpace = pdfRGB Then
For C = 1 To UBound(tempBuf) - 1 Step 3
ImgBuf(3 * kk + 1) = tempBuf(C + 2)
ImgBuf(3 * kk + 2) = tempBuf(C + 1)
ImgBuf(3 * kk + 3) = tempBuf(C)
If (((kk + 1) Mod BMPI.BMPH.biWidth) = 0) And blnFlag Then C = C + (BMPI.BMPH.biWidth Mod 4)
kk = kk + 1
Next
Else
For C = 1 To UBound(tempBuf) - 1 Step 3
lngGray = 0.33 * tempBuf(C + 2) + 0.59 * tempBuf(C + 1) + 0.11 * tempBuf(C)
ImgBuf(kk + 1) = IIf(lngGray > 255, 255, lngGray)
If (((kk + 1) Mod BMPI.BMPH.biWidth) = 0) And blnFlag Then C = C + (BMPI.BMPH.biWidth Mod 4)
kk = kk + 1
Next
ReDim Preserve ImgBuf(1 To kk)
End If
ElseIf BPP <= 8 Then
blnFlag = (BMPI.BMPH.biWidth Mod 16) <> 0
For i = 1 To UBound(tempBuf)
ImgBuf(kk + 1) = tempBuf(i)
If ((kk + 1) Mod Int((BMPI.BMPH.biWidth + (8 / BPP) - 1) / (8 / BPP))) = 0 And blnFlag Then i = i + (XBMP - (i Mod XBMP))
kk = kk + 1
Next
ReDim Preserve ImgBuf(1 To kk)
End If
LeggeBMP = True
End If
End Function