Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
 GetImageEncoders Method
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
ImageCodecInfo..::.GetImageEncoders Method

Returns an array of ImageCodecInfo objects that contain information about the image encoders built into GDI+.

Namespace:  System.Drawing.Imaging
Assembly:  System.Drawing (in System.Drawing.dll)
Visual Basic (Declaration)
Public Shared Function GetImageEncoders As ImageCodecInfo()
Visual Basic (Usage)
Dim returnValue As ImageCodecInfo()

returnValue = ImageCodecInfo.GetImageEncoders()
C#
public static ImageCodecInfo[] GetImageEncoders()
Visual C++
public:
static array<ImageCodecInfo^>^ GetImageEncoders()
JScript
public static function GetImageEncoders() : ImageCodecInfo[]

Return Value

Type: array<System.Drawing.Imaging..::.ImageCodecInfo>[]()[]
An array of ImageCodecInfo objects. Each ImageCodecInfo object in the array contains information about one of the built-in image encoders.

The following example is designed for use with Windows Forms, and it requires PaintEventArgs e, which is a parameter of the Paint event handler. The code uses the GetImageEncoders method to retrieve all the codec information for all installed image encoders and codecs, and then draws all the information about each codec to the screen.

Visual Basic
Public Sub GetImageEncodersExample(ByVal e As PaintEventArgs)

    ' Get an array of available codecs.
    Dim myEncoders() As ImageCodecInfo
    myEncoders = ImageCodecInfo.GetImageEncoders()
    Dim numEncoders As Integer = myEncoders.GetLength(0)
    Dim strNumEncoders As String = numEncoders.ToString()
    Dim foreColor As Color = Color.Black
    Dim font As New Font("Arial", 8)
    Dim i As Integer = 0

    ' Get the info. for all encoders in the array.
    If numEncoders > 0 Then
        Dim myEncoderInfo(numEncoders * 10) As String
        For i = 0 To numEncoders - 1
            myEncoderInfo((i * 10)) = "Codec Name = " _
            + myEncoders(i).CodecName
            myEncoderInfo((i * 10 + 1)) = "Class ID = " _
            + myEncoders(i).Clsid.ToString()
            myEncoderInfo((i * 10 + 2)) = "DLL Name = " _
            + myEncoders(i).DllName
            myEncoderInfo((i * 10 + 3)) = "Filename Ext. = " _
            + myEncoders(i).FilenameExtension
            myEncoderInfo((i * 10 + 4)) = "Flags = " _
            + myEncoders(i).Flags.ToString()
            myEncoderInfo((i * 10 + 5)) = "Format Descrip. = " _
            + myEncoders(i).FormatDescription
            myEncoderInfo((i * 10 + 6)) = "Format ID = " _
            + myEncoders(i).FormatID.ToString()
            myEncoderInfo((i * 10 + 7)) = "MimeType = " _
            + myEncoders(i).MimeType
            myEncoderInfo((i * 10 + 8)) = "Version = " _
            + myEncoders(i).Version.ToString()
            myEncoderInfo((i * 10 + 9)) = " "
        Next i
        Dim numMyEncoderInfo As Integer = myEncoderInfo.GetLength(0)

        ' Render to the screen all the information.
        Dim j As Integer = 20
        For i = 0 To numMyEncoderInfo - 1
            e.Graphics.DrawString(myEncoderInfo(i), font, _
            New SolidBrush(foreColor), 20, j)
            j += 12
        Next i
    Else
        e.Graphics.DrawString("No Encoders Found", font, _
        New SolidBrush(foreColor), 20, 20)
    End If
End Sub
C#
private void GetImageEncodersExample(PaintEventArgs e)
{

    // Get an array of available codecs.
    ImageCodecInfo[] myCodecs;
    myCodecs = ImageCodecInfo.GetImageEncoders();
    int numCodecs = myCodecs.GetLength(0);

    //numCodecs = 1;

    // 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);
}
Visual C++
private:
    void GetImageEncodersExample(PaintEventArgs^ e)
    {
        // Get an array of available codecs.
        array<ImageCodecInfo^>^ codecInfo;
        codecInfo = ImageCodecInfo::GetImageEncoders();
        int numCodecs = codecInfo->GetLength(0);

        //numCodecs = 1;

        // Set up display variables.
        Color^ foreColor = Color::Black;
        Drawing::Font^ font = gcnew Drawing::Font("Arial", 8);

        // 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.
            array<String^>^ codecInfoStrings = 
                gcnew array<String^>(numCodecs * 10);

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

            // Render all of the information to the screen.
            int j = 20;
            for (int i = 0; i < numCodecInfo; i++)
            {
                e->Graphics->DrawString(codecInfoStrings[i],
                    font, gcnew SolidBrush(*foreColor), 20, (float)j);
                j += 12;
            }
        }
        else
            e->Graphics->DrawString("No Codecs Found",
                font, gcnew SolidBrush(*foreColor), 20, 20);
    }

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker