This documentation is archived and is not being maintained.

Encoder.Compression Field

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

[Visual Basic]
Public Shared ReadOnly Compression As Encoder
public static readonly Encoder Compression;
public: static Encoder* Compression;
public static var Compression : Encoder;


[C#] The following example creates a Bitmap object from a BMP file. The code saves the image as a TIFF file with LZW compression.

using System;
using System.Drawing;
using System.Drawing.Imaging;
class Example_SetTIFFCompression
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("Shapes.bmp");
// Get an ImageCodecInfo object that represents the TIFF codec.
myImageCodecInfo = GetEncoderInfo("image/tiff");
// Create an Encoder object based on the GUID
// for the Compression parameter category.
myEncoder = Encoder.Compression;
// 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 bitmap as a TIFF file with LZW compression.
myEncoderParameter = new EncoderParameter(
myEncoderParameters.Param[0] = myEncoderParameter;
myBitmap.Save("ShapesLZW.tif", 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;

[Visual Basic, C++, JScript] No example is available for Visual Basic, C++, or JScript. To view a C# example, click the Language Filter button Language Filter in the upper-left corner of the page.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

Encoder Class | Encoder Members | System.Drawing.Imaging Namespace