다음을 통해 공유


방법: 설치된 인코더 나열

응용 프로그램에서 특정 이미지 파일 형식을 저장할 수 있는지 여부를 확인하기 위해 컴퓨터에서 사용할 수 있는 이미지 인코더를 나열해야 할 수 있습니다. ImageCodecInfo 클래스에서는 이미지 인코더를 사용할 수 있는지 확인할 수 있도록 GetImageEncoders 정적 메서드를 제공합니다. GetImageEncodersImageCodecInfo 개체의 배열을 반환합니다.

예제

다음 코드 예제에서는 설치된 인코더와 해당 속성 값의 목록을 출력합니다.

Private Sub GetImageEncodersExample(ByVal e As PaintEventArgs)
    ' Get an array of available encoders.
    Dim myCodecs() As ImageCodecInfo
    myCodecs = ImageCodecInfo.GetImageEncoders()
    Dim numCodecs As Integer = myCodecs.GetLength(0)

    ' Set up display variables.
    Dim foreColor As Color = Color.Black
    Dim font As New Font("Arial", 8)
    Dim i As Integer = 0

    ' Check to determine whether any codecs were found.
    If numCodecs > 0 Then

        ' Set up an array to hold codec information. There are 9
        ' information elements plus 1 space for each codec, so 10 times
        ' the number of codecs found is allocated.
        Dim myCodecInfo(numCodecs * 10) As String

        ' Write all the codec information to the array.
        For i = 0 To numCodecs - 1
            myCodecInfo((i * 10)) = "Codec Name = " + myCodecs(i).CodecName
            myCodecInfo((i * 10 + 1)) = "Class ID = " + myCodecs(i).Clsid.ToString()
            myCodecInfo((i * 10 + 2)) = "DLL Name = " + myCodecs(i).DllName
            myCodecInfo((i * 10 + 3)) = "Filename Ext. = " + myCodecs(i).FilenameExtension
            myCodecInfo((i * 10 + 4)) = "Flags = " + myCodecs(i).Flags.ToString()
            myCodecInfo((i * 10 + 5)) = "Format Descrip. = " + myCodecs(i).FormatDescription
            myCodecInfo((i * 10 + 6)) = "Format ID = " + myCodecs(i).FormatID.ToString()
            myCodecInfo((i * 10 + 7)) = "MimeType = " + myCodecs(i).MimeType
            myCodecInfo((i * 10 + 8)) = "Version = " + myCodecs(i).Version.ToString()
            myCodecInfo((i * 10 + 9)) = " "
        Next i
        Dim numMyCodecInfo As Integer = myCodecInfo.GetLength(0)

        ' Render all of the information to the screen.
        Dim j As Integer = 20
        For i = 0 To numMyCodecInfo - 1
            e.Graphics.DrawString(myCodecInfo(i), _
                font, New SolidBrush(foreColor), 20, j)
            j += 12
        Next i
    Else
        e.Graphics.DrawString("No Codecs Found", _
            font, New SolidBrush(foreColor), 20, 20)
    End If

End Sub
        private void GetImageEncodersExample(PaintEventArgs e)
        {
            // Get an array of available encoders.
            ImageCodecInfo[] myCodecs;
            myCodecs = ImageCodecInfo.GetImageEncoders();
            int numCodecs = myCodecs.GetLength(0);

            // Set up display variables.
            Color foreColor = Color.Black;
            Font font = new Font("Arial", 8);
            int i = 0;

            // Check to determine whether any codecs were found.
            if (numCodecs > 0)
            {
                // Set up an array to hold codec information. There are 9
                // information elements plus 1 space for each codec, so 10 times
                // the number of codecs found is allocated.
                string[] myCodecInfo = new string[numCodecs * 10];

                // Write all the codec information to the array.
                for (i = 0; i < numCodecs; i++)
                {
                    myCodecInfo[i * 10] = "Codec Name = " + myCodecs[i].CodecName;
                    myCodecInfo[(i * 10) + 1] = "Class ID = " +
                        myCodecs[i].Clsid.ToString();
                    myCodecInfo[(i * 10) + 2] = "DLL Name = " + myCodecs[i].DllName;
                    myCodecInfo[(i * 10) + 3] = "Filename Ext. = " +
                        myCodecs[i].FilenameExtension;
                    myCodecInfo[(i * 10) + 4] = "Flags = " +
                        myCodecs[i].Flags.ToString();
                    myCodecInfo[(i * 10) + 5] = "Format Descrip. = " +
                        myCodecs[i].FormatDescription;
                    myCodecInfo[(i * 10) + 6] = "Format ID = " +
                        myCodecs[i].FormatID.ToString();
                    myCodecInfo[(i * 10) + 7] = "MimeType = " + myCodecs[i].MimeType;
                    myCodecInfo[(i * 10) + 8] = "Version = " +
                        myCodecs[i].Version.ToString();
                    myCodecInfo[(i * 10) + 9] = " ";
                }
                int numMyCodecInfo = myCodecInfo.GetLength(0);

                // Render all of the information to the screen.
                int j = 20;
                for (i = 0; i < numMyCodecInfo; i++)
                {
                    e.Graphics.DrawString(myCodecInfo[i],
                        font,
                        new SolidBrush(foreColor),
                        20,
                        j);
                    j += 12;
                }
            }
            else
                e.Graphics.DrawString("No Codecs Found",
                    font,
                    new SolidBrush(foreColor),
                    20,
                    20);
        }

코드 컴파일

이 예제에는 다음 사항이 필요합니다.

참고 항목

작업

방법: 설치된 디코더 나열

기타 리소스

관리 GDI+에서 이미지 인코더 및 디코더 사용