3

特定のフォルダから画像のみをロードしようとしてサムネイル領域に表示する必要がある場合に表示するachecked list boxとaがありますthumbnail areaが、問題はthumbs.db、チェックされていないリストボックスにも追加されているファイルがあることです。それが必要。

では、thumbs.dbファイルなしで実際に画像ファイルのみをロードするにはどうすればよいですか。

これが私のコードです:

Private Sub LoadProjectToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles LoadProjectToolStripMenuItem.Click
    Using ofdlg As New Windows.Forms.OpenFileDialog

        ofdlg.DefaultExt = "trk"
        ofdlg.Filter = "Project|*.trk"
        ofdlg.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
        If ofdlg.ShowDialog = Windows.Forms.DialogResult.OK Then

            Dim SaveData As New gCanvasData
            Using objStreamReader As New StreamReader(ofdlg.FileName)
                Dim x As New XmlSerializer(GetType(gCanvasData))
                SaveData = CType(x.Deserialize(objStreamReader), gCanvasData)
                objStreamReader.Close()
            End Using

            With SaveData
                'gTSSizer_gAZoom.Value = 100
                GCanvas1.ImageXYReset()
                GCanvas1.Image = .Image
                GCanvas1.gAnnotates = .gAnnotates
                GCanvas1.RebuildAll()
                GCanvas1.AssembleBitmap()
            End With

            Dim fullpath As String
            fullpath = Application.StartupPath + "\" & System.IO.Path.GetFileNameWithoutExtension(ofdlg.FileName) + "\"

            For Each fi As FileInfo In New DirectoryInfo(fullpath).GetFiles
                CheckedListBox1.Items.Add(Application.StartupPath + "\" & System.IO.Path.GetFullPath(ofdlg.FileName))
                For i As Integer = 0 To CheckedListBox1.Items.Count - 1
                    CheckedListBox1.SetItemChecked(i, True)
                    ThumbControl1.AddFolder(fullpath, True)
                Next i
            Next
        End If
    End Using
End Sub
4

3 に答える 3

2

ForEachLoop内でフィルタリングします。

For Each fi As FileInfo In New DirectoryInfo(fullpath).GetFiles
    If Not {".jpg", ".png", ".bmp"}.Contains(fi.Extension) Then Continue For
    ' ...
Next

またはGetFilesでそれを行います:

DirectoryInfo(fullpath).GetFiles(".jpg")
于 2012-10-25T14:59:46.977 に答える
2

ついに解決策を見つけました:

Dim fullpath As String
fullpath = Application.StartupPath & "\" & System.IO.Path.GetFileNameWithoutExtension(ofdlg.FileName) + "\"


Dim FileDirectory As New IO.DirectoryInfo(fullpath)
Dim FileJpg As IO.FileInfo() = FileDirectory.GetFiles("*.jpg")
Dim FileGif As IO.FileInfo() = FileDirectory.GetFiles("*.gif")
Dim FileBmp As IO.FileInfo() = FileDirectory.GetFiles("*.bmp")

For Each File As IO.FileInfo In FileJpg
CheckedListBox1.Items.Add(File.FullName)
Dim str As String
str = Directory.GetCurrentDirectory() & "\" & "Backup\"
       Next
         For Each File As IO.FileInfo In FileGif
                CheckedListBox1.Items.Add(File.FullName)
                Dim str As String
                str = Directory.GetCurrentDirectory() & "\" & "Backup\"
            Next
            For Each File As IO.FileInfo In FileBmp
                CheckedListBox1.Items.Add(File.FullName)
                Dim str As String
                str = Directory.GetCurrentDirectory() & "\" & "Backup\"
            Next
            For i As Integer = 0 To CheckedListBox1.Items.Count - 1
                CheckedListBox1.SetItemChecked(i, True)
            Next i
于 2012-10-25T15:32:56.323 に答える
0

DirectoryInfo(fullpath).GetFilesをDirectoryInfo(fullpath).EnumerateFiles()に変更し、必要な画像ファイル拡張子の検索パターンを追加します。
http://msdn.microsoft.com/en-us/library/dd383574.aspx

于 2012-10-25T14:40:45.440 に答える