get pixel height and width ( and depth?) in vb6 from an image file

How do i get the pixel height and width properties on a specific jpg file in vb6?
I dont mind a frigged way of doing it as its for a once off program  run to validate a whole lot of files.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike TomlinsonMiddle School Assistant TeacherCommented:
Something like this:

Private Sub Command1_Click()
    On Error GoTo cancelled:
    Dim img As StdPicture
    Dim imgWidth As Single
    Dim imgHeight As Single
    CommonDialog1.Filter = "Pictures (*.jpg;*.bmp;*.gif)|*.jpg;*.bmp;*.gif"
    Set img = LoadPicture(CommonDialog1.FileName)
    imgWidth = Round(Me.ScaleX(img.Width, vbHimetric, vbPixels))
    imgHeight = Round(Me.ScaleY(img.Height, vbHimetric, vbPixels))
    MsgBox CommonDialog1.FileName & vbCrLf & imgWidth & "x" & imgHeight
End Sub

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
the following will get the height and width info from a jpg.
Hope it helps some    

    Dim sFilePath As String
    Dim lFileNum As Long
    Dim lJPGStart As Long
    Dim sBuff As String
    Dim lTemp As Long
    Dim lHeight As Long
    Dim lWidth As Long

    sFilePath = "C:\test.jpg"
    ' Read the JPG file into memory
    lFileNum = FreeFile
    Open sFilePath For Binary Access Read As lFileNum
    sBuff = Space(LOF(1))
    Get #lFileNum, 1, sBuff
    Close lFileNum
    ' Look for the image info block (FF,C0)
    If Mid(sBuff, 1, 2) <> Chr(&HFF) & Chr(&HD8) Then
        MsgBox "Not a valid JPG file"
        lJPGStart = 2
                lJPGStart = lJPGStart + 1
                If Mid(sBuff, lJPGStart - 1, 1) = Chr(&HFF) And Mid(sBuff, lJPGStart, 1) <> Chr(&HFF) Then Exit Do

            Select Case Asc(Mid(sBuff, lJPGStart, 1))
                Case &HC0 To &HC3, &HC5 To &HC7, &HC9 To &HCB, &HCD To &HCF: Exit Do
            End Select
            lJPGStart = lJPGStart + ((CLng(Asc(Mid(sBuff, lJPGStart + 1, 1))) * 256) + Asc(Mid(sBuff, lJPGStart + 2)))

            If lJPGStart >= Len(sBuff) Then
                MsgBox "bad JPG file"
                Exit Do
            End If
        ' Fetch the image hight and with
        lHeight = ((CLng(Asc(Mid(sBuff, lJPGStart + 4, 1))) * 256) + Asc(Mid(sBuff, lJPGStart + 5)))
        lWidth = ((CLng(Asc(Mid(sBuff, lJPGStart + 6, 1))) * 256) + Asc(Mid(sBuff, lJPGStart + 7)))
        MsgBox "Height = " & lHeight & vbCrLf & "Width = " & lWidth
    End If
brianhardingAuthor Commented:
terrifc thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.