2020年5月22日 星期五

vb.net 列出所有Image的副檔名 [List all Image extension]

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
    Private Function GetImageFilter() As String
        Dim allImageExtensions As StringBuilder = New StringBuilder()
        Dim separator As String = ""
        Dim codecs As ImageCodecInfo() = ImageCodecInfo.GetImageEncoders()
        Dim images As Dictionary(Of String, String) = New Dictionary(Of String, String)()
        For Each codec As ImageCodecInfo In codecs
            allImageExtensions.Append(separator)
            allImageExtensions.Append(codec.FilenameExtension)
            separator = ";"
            images.Add(String.Format("{0} Files ({1})", codec.FormatDescription, codec.FilenameExtension), codec.FilenameExtension)
        Next
        
        Dim sb As StringBuilder = New StringBuilder()
        If allImageExtensions.Length > 0 Then
            sb.AppendFormat("{0}|{1}", "All Images", allImageExtensions.ToString())
        End If

        images.Add("All Files", "*.*")
        For Each image As KeyValuePair(Of String, String) In images
            sb.AppendFormat("|{0}|{1}", image.Key, image.Value)
        Next

        Return sb.ToString()
    End Function

沒有留言:

張貼留言