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), ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access