O'Reilly logo

.NET Windows Forms in a Nutshell by Matthew Adams, Ian Griffiths

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

Bitmap

Synopsis

This subclass of Image encapsulates a picture represented by a 2D array of pixel data. It supports a range of PixelFormats, including both true-color and palette-color bitmaps, and those with an alpha channel for transparency.

A Bitmap conceptually represents a system bitmap and is ultimately implemented through a native GDI+ bitmap handle. As with most drawing classes that wrap limited resources (Pen and Brush being other examples), you should have a well-defined lifetime management plan, calling Dispose() when you are finished to release the resources back to the system (the using idiom in C# is useful here: see the main body of the text for details). If you rely on the garbage collector to do this, the Bitmap object will be collected but its pixel data will be leaked until the garbage collector happens to run, which may be too late.

There are several ways to construct a Bitmap object. One of the most is common is to provide the filename of the picture that you want to load. The framework will use the installed CODECs (BMP, PNG, JPG, and GIF) to attempt to load the image. Note that the file itself will remain locked until the Bitmap that loaded it is disposed. However, you can Clone() the bitmap and Dispose() the original to release the file.

Alternatively, you can construct bitmaps of a specific size and PixelFormat, or bitmaps compatible with a particular Graphics surface. You can also construct from another Image (optionally rescaling the original in the process), ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required