ReadBitmapFile

In Class PicBMP

  63 Private Function ReadBitmapFile(ByVal Filename As String) As Boolean
  64 ' Read picture information from a bitmap file of type BMP/DIB/RLE
  65 ' [Filename] Name of picture file
  66 ' Return value:
  67 ' True - Picture information retrieved
  68 ' False - Not a valid bitmap file
  69 
  70 Dim BMPFileHeader As BITMAPFILEHEADER ' Main BM file header
  71 Dim FileNr As Integer  ' Number of open file
  72 Dim HeaderSize As Long ' Size of header data in bytes
  73 
  74 IsRLE = False        ' Clear the IsRLE flag. We will set it below to True if required.
  75 BMPType = bmpUnknown ' Set file type to bmpUnknown until we can verify the real type
  76 
  77 ' Open the file for binary read access
  78 FileNr = FreeFile
  79 Open Filename For Binary Access Read Lock Write As #FileNr
  80 
  81 If LOF(FileNr) > Len(BMPFileHeader) Then
  82     ' File length is "enough", read main BM file header header
  83     Get #FileNr, 1, BMPFileHeader
  84     If BMPFileHeader.bfType = &H4D42 Then ' BM
  85         If BMPFileHeader.bfReserved1 = 0 And BMPFileHeader.bfReserved2 = 0 Then
  86             ' Signature OK
  87         
  88             ' Retrieve size of following header
  89             Get #FileNr, , HeaderSize
  90             Seek #FileNr, Seek(FileNr) - 4 ' Rewind to start of header
  91             
  92             Select Case HeaderSize
  93                 Case Len(CoreHeader)
  94                     Get #FileNr, , CoreHeader
  95                     BMPType = bmpCoreHeader
  96                     ReadBitmapFile = True ' File valid
  97                 Case Len(InfoHeader)
  98                     Get #FileNr, , InfoHeader
  99                     BMPType = bmpInfoHeader
 100                     
 101                     ' Determine bitmap compression
 102                     Select Case InfoHeader.biCompression
 103                         Case BI_RLE8, BI_RLE4
 104                             ' The bitmap is RLE compressed
 105                             IsRLE = True
 106                     End Select
 107                     ReadBitmapFile = True ' File valid
 108                 Case Else
 109                     ReadBitmapFile = False ' Invalid/unsupported file type
 110             End Select
 111         End If
 112     End If
 113 End If
 114 Close FileNr
 115 
 116 End Function
 117 
 118 

Called by

IPicInfo_ReadFile