Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Image properties

Status
Not open for further replies.

ginzing

Programmer
Jul 3, 2001
7
ZA
Hi I am a newbie in visual basic and I am faced with the challenge of writting a component that can read the properties of an image. The component has to be passed the image name and then it should return the height and width of this image in pixels, the size of of the image in bytes.
Your help will be appreciatted.

Gin
 
You should try to search in the direction of API-functions. These are functions that Windows use.

good luck!!

greetings

Mim
 
Check the info about the header of each image file format.
I know that at the fist couple of bytes are the w & h.

Use
Code:
FileLen(filename as string) as long
to know the file size.


::)

bluenote@uyuyuy.com
(excuse my english)
 
Thanks you both for your help. I just need to know where I can find information on APIs VBmim.

Gin
B-)
 
You don't really need the API for this task. What you seem to be asking is for something like the following to provide meaningful output

Private Sub Command1_Click()
Dim bmpResult As BitmapInfo
Call GetBitmapInfo("c:\horde1.bmp", bmpResult)
Debug.Print "Size: " & bmpResult.bmSize & " bytes"
Debug.Print "Width: " & bmpResult.bmWidth & " pixels"
Debug.Print "Height: " & bmpResult.bmHeight & " pixels"
End Sub


If so, then just add the following to a module:

Option Explicit

Private Type BITMAPFILEHEADER
bfType As Integer
bfSize As Long
bfReserved1 As Integer
bfReserved2 As Integer
bfOffBits As Long
End Type

Private Type BITMAP
bmType As Long
bmWidth As Long
bmHeight As Long
bmWidthBytes As Long
bmPlanes As Integer
bmBitsPixel As Integer
bmBits As Long
End Type

Public Type BitmapInfo
bmSize As Long
bmWidth As Long
bmHeight As Long
End Type


Public Sub GetBitmapInfo(strBitmap As String, ByRef bmpResult As BitmapInfo)
Dim myBmpHeader As BITMAPFILEHEADER
Dim myBmp As BITMAP
Dim hFile As Long

hFile = FreeFile
Open strBitmap For Binary As hFile
Get hFile, , myBmpHeader
Get hFile, , myBmp
Close hFile
bmpResult.bmHeight = myBmp.bmHeight
bmpResult.bmWidth = myBmp.bmWidth
bmpResult.bmSize = myBmpHeader.bfSize

End Sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top