How to Return the Width/Height of a picture
Posted on January 5, 2009
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | 'Graphics - How to Return the Width/Height of a picture Option Explicit Private Type BITMAPFILEHEADER bfType As Integer bfSize As Long bfReserved1 As Integer bfReserved2 As Integer bfOffBits As Long End Type 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 Public Function EWidth(ByVal strFileName As String) As Long Dim lngFile As Long Dim udtFileHeader As BITMAPFILEHEADER Dim udtFileInfo As BITMAPINFOHEADER lngFile = FreeFile Open strFileName For Binary As lngFile Get #lngFile, , udtFileHeader Get #lngFile, , udtFileInfo EWidth = udtFileInfo.biWidth Close lngFile End Function Public Function EHeight(ByVal strFileName As String) As Long Dim lngFile As Long Dim udtFileHeader As BITMAPFILEHEADER Dim udtFileInfo As BITMAPINFOHEADER lngFile = FreeFile Open strFileName For Binary As lngFile Get #lngFile, , udtFileHeader Get #lngFile, , udtFileInfo EHeight = udtFileInfo.biHeight Close lngFile End Function 'How can I use these functions: Private Sub Command1_Click() lngHeight = EHeight("pic.bmp") lngWidth = EWidth("pic.bmp") End Sub |