Как прочитать BMP файл - VB
Формулировка задачи:
У меня например есть файл, расположенный 'C: emp.bmp'
Как мне следующим образом отобразить его содержимое в графическом виде.
С какого байта начинать чтение?
Такой вариант почему-то не катит.
Подскажите пожалуйста
Листинг программы
- Private Type BITMAPINFOHEADER '40 bytes
- biSize As Long
- biWidth As Long
- biHeight As Long
- biPlanes As Integer
- biBitCount As Integer
- biCompression As Long
- biSizeImage As Long
- biXPelsPerMeter As Long
- biYPelsPerMeter As Long
- biClrUsed As Long
- biClrImportant As Long
- End Type
- Private Type BITMAPFILEHEADER '14 bytes
- bfType As String * 2 ''magic cookie' - must be 'BM'
- bfSize As Long
- bfReserved1 As Integer
- bfReserved2 As Integer
- bfOffBits As Long
- End Type
- Private Type BITMAPINFO
- bmiHeader As BITMAPINFOHEADER
- bmiColors() As Long 'array of RGBQUADs
- End Type
- Private Type palette
- R As Byte
- G As Byte
- B As Byte
- End Type
- Public bmih As BITMAPINFOHEADER
- Dim palette As palette
- Public Function BMPFillInfoStruct(ByVal filename As String) As Boolean
- Dim hFile As Long
- Dim bfh As BITMAPFILEHEADER
- hFile = FreeFile()
- On Error Resume Next
- Open filename For Binary Access Read As #hFile
- Get #hFile, , bfh
- Get #hFile, 15, bmih 'start at the 15th byte
- WritePos = 55
- For yy = 0 To bmih.biHeight
- For xx = 0 To bmih.biWidth
- Get #hFile, WritePos, palette
- Form1.Picture1.PSet (xx, yy), RGB(palette.R, palette.G, palette.B)
- WritePos = WritePos + Len(palette)
- Next xx
- Next yy
- Close #hFile 'Close file
- BMPFillInfoStruct = True 'indicate success
- End Function
Решение задачи: «Как прочитать BMP файл»
textual
Листинг программы
- Private Type BITMAPFILEHEADER '14 bytes
- bfType As String * 2 ''magic cookie' - must be 'BM'
- bfSize As Long
- bfReserved1 As Integer
- bfReserved2 As Integer
- bfOffBits As Long
- End Type
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д