Export (0) Print
Expand All

Encoder.ColorDepth Field

An Encoder object that is initialized with the globally unique identifier for the color depth parameter category.

Namespace: System.Drawing.Imaging
Assembly: System.Drawing (in system.drawing.dll)

public static readonly Encoder ColorDepth
public static final Encoder ColorDepth
public static final var ColorDepth : Encoder
Not applicable.

The following example creates a Bitmap object from a BMP file. The code saves the image as a TIFF file with a color depth of 24 bits per pixel.

using System;
using System.Drawing;
using System.Drawing.Imaging;
class Example_SetColorDepth
{
    public static void Main()
    {
        Bitmap myBitmap;
        ImageCodecInfo myImageCodecInfo;
        Encoder myEncoder;
        EncoderParameter myEncoderParameter;
        EncoderParameters myEncoderParameters;
                     
        // Create a Bitmap object based on a BMP file.
        myBitmap = new Bitmap(@"C:\Documents and Settings\All Users\Documents\My Music\music.bmp");
                     
        // Get an ImageCodecInfo object that represents the TIFF codec.
        myImageCodecInfo = GetEncoderInfo("image/tiff");
                     
        // Create an Encoder object based on the GUID
        // for the ColorDepth parameter category.
        myEncoder = Encoder.ColorDepth;
                     
        // Create an EncoderParameters object.
        // An EncoderParameters object has an array of EncoderParameter
        // objects. In this case, there is only one
        // EncoderParameter object in the array.
        myEncoderParameters = new EncoderParameters(1);
                     
        // Save the image with a color depth of 24 bits per pixel.
        myEncoderParameter =
            new EncoderParameter(myEncoder, 24L);
        myEncoderParameters.Param[0] = myEncoderParameter;
        myBitmap.Save("Shapes24bpp.tiff", myImageCodecInfo, myEncoderParameters);
    }

    private static ImageCodecInfo GetEncoderInfo(String mimeType)
    {
        int j;
        ImageCodecInfo[] encoders;
        encoders = ImageCodecInfo.GetImageEncoders();
        for(j = 0; j < encoders.Length; ++j)
        {
            if(encoders[j].MimeType == mimeType)
                return encoders[j];
        }
        return null;
    }
}

import System.* ;
import System.Drawing.* ;
import System.Drawing.Imaging.* ;

class Example_SetColorDepth
{
    public static void main(String[] args)
    {
        Bitmap myBitmap;
        ImageCodecInfo myImageCodecInfo;
        Encoder myEncoder;
        EncoderParameter myEncoderParameter;
        EncoderParameters myEncoderParameters;
        
        // Create a Bitmap object based on a BMP file.
        myBitmap = new Bitmap("C:\\Documents and Settings\\All Users"
            + "\\Documents\\My Music\\music.bmp");
        
        // Get an ImageCodecInfo object that represents the TIFF codec.
        myImageCodecInfo = GetEncoderInfo("image/tiff");
        
        // Create an Encoder object based on the GUID
        // for the ColorDepth parameter category.
        myEncoder = Encoder.ColorDepth;
        
        // Create an EncoderParameters object.
        // An EncoderParameters object has an array of EncoderParameter
        // objects. In this case, there is only one
        // EncoderParameter object in the array.
        myEncoderParameters = new EncoderParameters(1);
        
        // Save the image with a color depth of 24 bits per pixel.
        myEncoderParameter = new EncoderParameter(myEncoder, 24L);
        myEncoderParameters.get_Param().set_Item( 0 , myEncoderParameter );
        myBitmap.Save("Shapes24bpp.tiff", myImageCodecInfo, 
            myEncoderParameters);
    } //main

    private static ImageCodecInfo GetEncoderInfo(String mimeType) 
    {
        int j;
        ImageCodecInfo encoders[];
        encoders = ImageCodecInfo.GetImageEncoders();
        for (j = 0; j < encoders.length; j++) {
            if ( encoders[j].get_MimeType().Equals(mimeType)) {
                return encoders[j];
            }
        } 
        return null ;
    } //GetEncoderInfo
} //Example_SetColorDepth

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

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft