BitmapCompression

BitmapCompression enumeration

Specifies different bitmap compression methods.

public enum BitmapCompression : uint

Values

NameValueDescription
Rgb0No compression.
Rle81RLE 8-bit/pixel compression. Can be used only with 8-bit/pixel bitmaps.
Rle42RLE 4-bit/pixel compression. Can be used only with 4-bit/pixel bitmaps.
Bitfields3RGB bit fields. Can be used only with 16 and 32-bit/pixel bitmaps.
Jpeg4JPEG compression. The bitmap contains a JPEG image.
Png5PNG compression. The bitmap contains a PNG image.
AlphaBitfields6RGBA bit fields. Can be used only with 16 and 32-bit/pixel bitmaps.
Dxt1827611204DXT1 compression. The bitmap contains a texture.

Examples

The example shows how to export a BmpImage with the Rgb compression type.

[C#]

string sourcePath = "input.png";
// Load a PNG image from a file.
using (Image pngImage = Image.Load(sourcePath))
{
    // BMP image is saved with transparency support by default, that is achieved by using the BitmapCompression.Bitfields compression method. 
    // To save a BMP image with the Rgb compression method, the BmpOptions with the Compression property set to BitmapCompression.Rgb should be specified.
    pngImage.Save(outputPath, new BmpOptions() { Compression = BitmapCompression.Rgb });
}

The example shows how to export a BmpImage from a Png file while keeping the alpha channel, save a Bmp file with transparency.

[C#]

string sourcePath = "input.png";
// Load a PNG image from a file.
using (Image pngImage = Image.Load(sourcePath))
{
    // BMP image is saved with transparency support by default. 
    // If you want to explicitly specify such mode, the BmpOptions's Compression property should be set to BitmapCompression.Bitfields.
    // The BitmapCompression.Bitfields compression method is the default compression method in the BmpOptions.
    // So the same result of exporting a Bmp image with transparency can be achieved by either one of the following ways.
    // With an implicit default options:
    pngImage.Save(outputPath);
    // With an explicit default options:
    pngImage.Save(outputPath, new BmpOptions());
    // Specifying the BitmapCompression.Bitfields compression method:
    pngImage.Save(outputPath, new BmpOptions() { Compression = BitmapCompression.Bitfields });
}

See Also