0

我正在尝试使用 vb.net 中的 GetDetailsOf 获取图像或视频文件的分辨率,但我不明白如何将文件加载到 shell32.folderitem 中,所以我正在以一种非常迂回的方式进行操作。

    OpenFileDialog1.ShowDialog()
    Dim fi As New FileInfo(OpenFileDialog1.FileName)

    Dim shell As New Shell32.Shell
    Dim objFolder As Shell32.Folder

    objFolder = shell.NameSpace(fi.DirectoryName)
    For i As Integer = 0 To objFolder.Items.Count - 1
        If objFolder.Items(i).name = fi.Name Then

            Console.WriteLine(objFolder.GetDetailsOf(objFolder.Items(i), 31))
            Console.WriteLine(objFolder.GetDetailsOf(objFolder.Items(i), 282))
            Console.WriteLine(objFolder.GetDetailsOf(objFolder.Items(i), 280))
        End If
    Next

我只是在文件夹中循环,直到找到与我的文件匹配的内容。有没有更清洁、更快的方法来做到这一点?我只需要从完整文件名中获得一个 shell32.FolderItem。

另外,我可以依靠 Detail 31 始终是分辨率,而 280/282 是帧高/帧宽吗?我如何知道他们是否会在其他计算机上检索相同的详细信息,而无需在一堆其他计算机上进行测试?

谢谢。

4

2 回答 2

1
    Dim fi As New FileInfo(fileName)
    Dim shl As Shell32.Shell = New Shell32.Shell
    Dim dir As Shell32.Folder = shl.[NameSpace](fi.DirectoryName)
    Dim itm As Shell32.FolderItem = dir.Items().Item(fi.Name)
    Dim itm2 As Shell32.ShellFolderItem = DirectCast(itm, Shell32.ShellFolderItem)


    Dim str As String = dir.GetDetailsOf(itm2, 31)

这使它无需搜索文件即可工作。31 为我返回图像尺寸。DirectoryInfo 没有 shell32 "getdetailsof" 拥有的所有元数据。

于 2013-06-25T04:47:38.830 回答
0

有没有更清洁、更快的方法来做到这一点?

像这样的东西应该工作:

Imports System.IO

    Dim test() As FileSystemInfo = New DirectoryInfo("MyDirectoryPath").GetFileSystemInfos("MyImageFile")
    'MyImageFile is actually a search pattern string.  the result is an array 
    'containing info on every file in the folder that matches the search pattern.
    'If the pattern is unique then only one file will be returned and using
    'the FullName property will return the full path to the file.
    test(0).FullName()
    'Or just the Name property to return just the file name
    test(0).Name()
于 2013-06-24T03:57:13.067 回答