Results 1 to 10 of 10

Thread: How to read Dimension of .bmp file ??

Threaded View

  1. #6
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926

    Re: How to read Dimension of .bmp file ??

    If you don't want to load the picture into a picturebox, you can use the following code:

    vb Code:
    1. Option Explicit
    2. Private Type BITMAPFILEHEADER
    3.         bfType(1) As Byte
    4.         bfSize As Long
    5.         bfReserved1 As Integer
    6.         bfReserved2 As Integer
    7.         bfOffBits As Long
    8. End Type
    9. Private Type BITMAPINFOHEADER
    10.         biSize As Long
    11.         biWidth As Long
    12.         biHeight As Long
    13.         biPlanes As Integer
    14.         biBitCount As Integer
    15.         biCompression As Long
    16.         biSizeImage As Long
    17.         biXPelsPerMeter As Long
    18.         biYPelsPerMeter As Long
    19.         biClrUsed As Long
    20.         biClrImportant As Long
    21. End Type
    22. Private Sub GetBitmapSize(ByVal Bitmap As String, ByRef lWidth As Long, ByRef lHeight As Long)
    23. Dim hFile As Integer
    24. Dim bfh As BITMAPFILEHEADER
    25. Dim bih As BITMAPINFOHEADER
    26.     hFile = FreeFile
    27.     Open Bitmap For Binary Access Read Shared As #hFile
    28.     Get #hFile, , bfh
    29.     Get #hFile, , bih
    30.     Close #hFile
    31.     lWidth = bih.biWidth
    32.     lHeight = bih.biHeight
    33. End Sub
    34. Private Sub Command1_Click()
    35. Dim lngWidth As Long
    36. Dim lngHeight As Long
    37.     Call GetBitmapSize("c:\windows\zapotec.bmp", lngWidth, lngHeight)
    38.     MsgBox "Width: " & lngWidth & vbCrLf & "Height: " & lngHeight
    39. End Sub
    Last edited by Frans C; Mar 30th, 2007 at 03:23 AM.
    Frans

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width