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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get bitdepth of image using vba

Status
Not open for further replies.

wmbb

Technical User
Jul 17, 2005
320
NL
In the properties of an image you can see the bitdepth of the image botn in WinXP and Windows 7.
I'm using the code below to extract the bitdepth of the image in Windows 7 and it works fine.
Using the same code in WinXP is doesn't show the bitdepth although the bitdepth is shown in the properties.
Has anyone an idea how to modify the code to read out the bitdepth in windows 7 and in WinXP ?
Code:
Option Explicit
Sub RetrievingExtendedFileProperties()
Dim testfile As String
Dim arrHeaders(200)
Dim i As Integer
testfile = "c:\test.tif"
For i = 0 To 200
 arrHeaders(i) = GetExtendedProperty(testfile, i)
Next

MsgBox "Bit depth is: " & GetExtendedProperty(testfile, "bitdepth")

End Sub


Private Function GetExtendedProperty(strFile As String, Optional varProperty As Variant = 0) As String
    Dim fso As New FileSystemObject
    Dim myFolder As String

    With New Shell32.Shell
        myFolder = fso.GetParentFolderName(strFile)
        Select Case TypeName(varProperty)
            Case "String"
                GetExtendedProperty = .Namespace(myFolder).Items.Item(fso.GetFileName(strFile)).ExtendedProperty(varProperty)
            Case "Long", "Integer"
                GetExtendedProperty = .Namespace(myFolder).GetDetailsOf(.Namespace(myFolder).ParseName(fso.GetFileName(strFile)), varProperty)
            End Select
    End With
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top