Как прочитать BMP файл - VB

Узнай цену своей работы

Формулировка задачи:

У меня например есть файл, расположенный 'C: emp.bmp' Как мне следующим образом отобразить его содержимое в графическом виде. С какого байта начинать чтение? Такой вариант почему-то не катит. Подскажите пожалуйста
Листинг программы
  1. Private Type BITMAPINFOHEADER '40 bytes
  2. biSize As Long
  3. biWidth As Long
  4. biHeight As Long
  5. biPlanes As Integer
  6. biBitCount As Integer
  7. biCompression As Long
  8. biSizeImage As Long
  9. biXPelsPerMeter As Long
  10. biYPelsPerMeter As Long
  11. biClrUsed As Long
  12. biClrImportant As Long
  13. End Type
  14. Private Type BITMAPFILEHEADER '14 bytes
  15. bfType As String * 2 ''magic cookie' - must be 'BM'
  16. bfSize As Long
  17. bfReserved1 As Integer
  18. bfReserved2 As Integer
  19. bfOffBits As Long
  20. End Type
  21. Private Type BITMAPINFO
  22. bmiHeader As BITMAPINFOHEADER
  23. bmiColors() As Long 'array of RGBQUADs
  24. End Type
  25. Private Type palette
  26. R As Byte
  27. G As Byte
  28. B As Byte
  29. End Type
  30. Public bmih As BITMAPINFOHEADER
  31. Dim palette As palette
  32. Public Function BMPFillInfoStruct(ByVal filename As String) As Boolean
  33. Dim hFile As Long
  34. Dim bfh As BITMAPFILEHEADER
  35.  
  36. hFile = FreeFile()
  37. On Error Resume Next
  38. Open filename For Binary Access Read As #hFile
  39. Get #hFile, , bfh
  40. Get #hFile, 15, bmih 'start at the 15th byte
  41. WritePos = 55
  42. For yy = 0 To bmih.biHeight
  43. For xx = 0 To bmih.biWidth
  44. Get #hFile, WritePos, palette
  45. Form1.Picture1.PSet (xx, yy), RGB(palette.R, palette.G, palette.B)
  46. WritePos = WritePos + Len(palette)
  47. Next xx
  48. Next yy
  49. Close #hFile 'Close file
  50. BMPFillInfoStruct = True 'indicate success
  51. End Function

Решение задачи: «Как прочитать BMP файл»

textual
Листинг программы
  1. Private Type BITMAPFILEHEADER '14 bytes
  2.    bfType As String * 2 ''magic cookie' - must be 'BM'
  3.    bfSize As Long
  4.     bfReserved1 As Integer
  5.     bfReserved2 As Integer
  6.     bfOffBits As Long
  7. End Type

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

13   голосов , оценка 4.154 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут
Похожие ответы