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

Read bit depth of image file using VBA

Status
Not open for further replies.

wmbb

Technical User
Jul 17, 2005
320
NL
Is it possible to read the bit depth of a image file and store this in a variable ?
The bit depth is available in the properties of the file, looking in the windows explorer.
 
What image file format?

Cheers
Paul Edstein
[MS MVP - Word]
 
>The bit depth is available in the properties of the file, looking in the windows explorer

And we can look at exactly the same property. Image format doesn't matter, as long as it is one recognized by the shell (i.e. by Explorer). Here's a one line example:

Code:
[blue]MsgBox "Bit depth of F:\File Downloads\FC3BugScreen.png: " & CreateObject("Shell.Application").Namespace("F:\File Downloads").Items.Item("FC3BugScreen.png").ExtendedProperty("Bitdepth")[/blue]

You might want a quick look at for a little bit more info about these extended properties. Note that the English names listed for each property are not always the names used to index the property itself (Eg "Bit depth" versus "bitdepth") - each index obviously matches an specific integer (which differs for each OS ...), and there is an alternative method of getting the extended property if we know the actual index number

Here's a more generic function to return the info by passing either the index name or the index itself:

Code:
[blue][green]' Requires references to Microsoft Scripting Runtiime library and Microsoft Shell Controls and Automation library[/green]
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[/blue]

And might be called as follows:

MsgBox "Bit depth is " & GetExtendedProperty("F:\File Downloads\FC3BugScreen.png", "Bitdepth")
MsgBox "Date created: " & GetExtendedProperty("F:\File Downloads\FC3BugScreen.png", 4)
 
Thanks strongm, this works for me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top