BMP (Bitmap) is a standard image format mainly used on the Microsoft Windows platform. BMP images can range from black and white (1 bit per pixel) up to 32 bit color (16.7 million colors), so the bitmap image format can store both indexed and true color images. There are two main BMP formats exist: Windows bitmap formats and OS/2 bitmap format. All of these formats support RLE-type compression for 4 and 8 bits per pixel palette images.

MIME Type

image/bmp

File Extensions

*.bmp, *.dib.

Supported Pixel Formats

Description Read Write
1 bit palette-based (Windows) Yes Yes
1 bit palette-based (OS/2) Yes No
4 bit palette-based (Windows) Yes Yes
4 bit palette-based (OS/2) Yes No
8 bit palette-based (Windows) Yes Yes
8 bit palette-based (OS/2) Yes No
24 bit RGB (Windows) Yes Yes
24 bit RGB (OS/2) Yes No
32 bit RGB (Windows) Yes Yes
32 bit RGB (OS/2) Yes No

Encoder Options

Name Default Value Comments
BmpEncoderOptions.Compression
BmpFrame.Compression
CompressionType.None The compression type of the BMP file. It can be either uncompressed or use RLE compression for 4-bit and 8-bit bitmaps.

Examples

Loading BMP Files

The simplest way to load the BMP file is to pass its name to the constructor:

Visual Basic

Dim bitmap As New Aurigma.GraphicsMill.Bitmap("c:\Mountain.bmp")

C#

Aurigma.GraphicsMill.Bitmap bitmap = new Aurigma.GraphicsMill.Bitmap(@"c:\Mountain.bmp");

Alternatively, if you already have an instance of the Bitmap, you can use the Load method:

Visual Basic

Dim bitmap As New Aurigma.GraphicsMill.Bitmap
bitmap.Load("c:\Mountain.bmp")

C#

Aurigma.GraphicsMill.Bitmap bitmap = new Aurigma.GraphicsMill.Bitmap();
bitmap.Load(@"c:\Mountain.bmp");        

Saving BMP Files

This code example saves the BMP image with RLE compression:

Visual Basic

Dim bitmap As New Aurigma.GraphicsMill.Bitmap("c:\Mountain.gif")

bitmap.Save("C:\Mountain.bmp", New Aurigma.GraphicsMill.Codecs.BmpEncoderOptions( _
    Aurigma.GraphicsMill.Codecs.CompressionType.Rle))

bitmap.Dispose()

C#

using (Aurigma.GraphicsMill.Bitmap bitmap = 
           new Aurigma.GraphicsMill.Bitmap(@"C:\Mountain.gif"))
{
    bitmap.Save(@"C:\Mountain.bmp", new Aurigma.GraphicsMill.Codecs.BmpEncoderOptions(
        Aurigma.GraphicsMill.Codecs.CompressionType.Rle));
}

You can also use BmpWriter class instead of the Save method of the Bitmap. In particular it enables you to save the image asynchronously.

The BmpWriter class usage is demonstrated below:

Visual Basic

Dim bitmap As New Aurigma.GraphicsMill.Bitmap("c:\Mountain.jpg")

Dim writer As New Aurigma.GraphicsMill.Codecs.BmpWriter("C:\Mountain.bmp")

Dim frame As New Aurigma.GraphicsMill.Codecs.BmpFrame( _
    Aurigma.GraphicsMill.Codecs.CompressionType.None)

frame.SetBitmap(bitmap)

bitmap.Dispose()

writer.AddFrame(frame)

frame.Dispose()

writer.Dispose()

C#

using (Aurigma.GraphicsMill.Bitmap bitmap = 
           new Aurigma.GraphicsMill.Bitmap(@"c:\Mountain.jpg"))
{
    using (Aurigma.GraphicsMill.Codecs.BmpWriter writer = 
        new Aurigma.GraphicsMill.Codecs.BmpWriter())
    {
        writer.Open(@"C:\Mountain.bmp");

        using (Aurigma.GraphicsMill.Codecs.BmpFrame frame = 
                   new Aurigma.GraphicsMill.Codecs.BmpFrame())
        {
            frame.Compression = Aurigma.GraphicsMill.Codecs.CompressionType.None;
            frame.SetBitmap(bitmap);

            writer.AddFrame(frame);
        }
    }
}