Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

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)

public static ImageCodecInfo[] GetImageEncoders()

Return Value

Type: 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.

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);
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft