View Single Post
  #4  
Old 16-01-2005, 09:29
drg
Guest
 
Posts: n/a
Default

Ок, I have thought up the function for reading BMP-24bit:

Code:
Private Type RGB
    RGB_R As Byte
    RGB_G As Byte
    RGB_B As Byte
End Type

Type BMP_Picture
    With As Long
    Height As Long
   ' Len As Long
    Point() As RGB
End Type

Function Read_BMP_Picture(ByVal FileName As String, _
                          ByRef BMP As BMP_Picture) As Boolean
'======================================================
' Ôóíêöèÿ äëÿ ÷òåíèÿ BMP-24 bit â ìàññèâ
'======================================================
Read_BMP_Picture = False
'On Error GoTo 10
Open FileName For Binary As #1 Len = 1
Dim P As Byte
BMP.Height = 0: BMP.With = 0
    Get #1, 19, P
    BMP.With = BMP.With + P
    Get #1, 20, P
    BMP.With = BMP.With + P * 256
    Get #1, 21, P
    BMP.With = BMP.With + P * 65536
    Get #1, 22, P
    BMP.With = BMP.With + P * 16777216
    Get #1, 23, P
    BMP.Height = BMP.Height + P
    Get #1, 24, P
    BMP.Height = BMP.Height + P * 256
    Get #1, 25, P
    BMP.Height = BMP.Height + P * 65536
    Get #1, 26, P
    BMP.Height = BMP.Height + P * 16777216
    
ReDim BMP.Point(BMP.With, BMP.Height)

Dim q As Long
Dim x As Single, y As Single
q = 52

For y = 1 To BMP.Height
    For x = 1 To BMP.With
        q = q + 3
        Get #1, q, BMP.Point(x, y).RGB_B
        Get #1, q + 1, BMP.Point(x, y).RGB_G
        Get #1, q + 2, BMP.Point(x, y).RGB_R
    Next
    q = q + 2
Next

Close #1
Read_BMP_Picture = True
Exit Function
10
End Function
Reply With Quote