Class Bitmap
Raster image stored as a managed byte array (top-down, BGRA / BGR layout). BMP file I/O is supported natively; other formats throw NotSupportedException.
Implements
Inherited Members
Namespace: DRIT.Drawing.Imaging
Assembly: DRIT.Drawing.dll
Syntax
public sealed class Bitmap : Image, IDisposable
Constructors
Bitmap(Image)
Initializes a new Bitmap as a copy of an existing image.
Declaration
public Bitmap(Image original)
Parameters
| Type | Name | Description |
|---|---|---|
| Image | original | The image to copy from. |
Bitmap(Stream)
Initializes a new Bitmap from the specified stream.
Declaration
public Bitmap(Stream stream)
Parameters
| Type | Name | Description |
|---|---|---|
| Stream | stream | The stream to load from. |
Bitmap(int, int)
Initializes a new Bitmap with the specified width and height.
Declaration
public Bitmap(int width, int height)
Parameters
| Type | Name | Description |
|---|---|---|
| int | width | The width of the bitmap. |
| int | height | The height of the bitmap. |
Bitmap(int, int, PixelFormat)
Initializes a new Bitmap with the specified width, height, and pixel format.
Declaration
public Bitmap(int width, int height, PixelFormat format)
Parameters
| Type | Name | Description |
|---|---|---|
| int | width | The width of the bitmap. |
| int | height | The height of the bitmap. |
| PixelFormat | format | The pixel format of the bitmap. |
Bitmap(int, int, int, PixelFormat, IntPtr)
Initializes a new Bitmap from an external pixel buffer.
Declaration
public Bitmap(int width, int height, int stride, PixelFormat format, IntPtr scan0)
Parameters
| Type | Name | Description |
|---|---|---|
| int | width | The width of the bitmap. |
| int | height | The height of the bitmap. |
| int | stride | The stride (bytes per row) of the pixel buffer. |
| PixelFormat | format | The pixel format of the bitmap. |
| IntPtr | scan0 | A pointer to the pixel buffer. |
Bitmap(string)
Initializes a new Bitmap from the specified file.
Declaration
public Bitmap(string filename)
Parameters
| Type | Name | Description |
|---|---|---|
| string | filename | The file to load from. |
Properties
Flags
Gets the flags for this bitmap.
Declaration
public override int Flags { get; }
Property Value
| Type | Description |
|---|---|
| int |
Overrides
Height
Gets the height of this bitmap in pixels.
Declaration
public override int Height { get; }
Property Value
| Type | Description |
|---|---|
| int |
Overrides
PixelFormat
Gets the pixel format of this bitmap.
Declaration
public override PixelFormat PixelFormat { get; }
Property Value
| Type | Description |
|---|---|
| PixelFormat |
Overrides
RawFormat
Gets the format of this bitmap.
Declaration
public override ImageFormat RawFormat { get; }
Property Value
| Type | Description |
|---|---|
| ImageFormat |
Overrides
Width
Gets the width of this bitmap in pixels.
Declaration
public override int Width { get; }
Property Value
| Type | Description |
|---|---|
| int |
Overrides
Methods
Clone()
Creates an exact copy of this Bitmap.
Declaration
public override Image Clone()
Returns
| Type | Description |
|---|---|
| Image | A new Bitmap with the same pixel data. |
Overrides
Clone(Rectangle, PixelFormat)
Creates a copy of the specified region of this Bitmap in the specified format.
Declaration
public Bitmap Clone(Rectangle rect, PixelFormat format)
Parameters
| Type | Name | Description |
|---|---|---|
| Rectangle | rect | The region to clone. |
| PixelFormat | format | The pixel format for the cloned bitmap. |
Returns
| Type | Description |
|---|---|
| Bitmap | The cloned bitmap. |
Dispose(bool)
Releases the unmanaged resources used by this bitmap and optionally releases the managed resources.
Declaration
protected override void Dispose(bool disposing)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | disposing |
|
Overrides
FromFile(string)
Creates a Bitmap from the specified file.
Declaration
public static Bitmap FromFile(string filename)
Parameters
| Type | Name | Description |
|---|---|---|
| string | filename | The file to load from. |
Returns
| Type | Description |
|---|---|
| Bitmap | The loaded bitmap. |
FromStream(Stream)
Creates a Bitmap from the specified stream.
Declaration
public static Bitmap FromStream(Stream stream)
Parameters
| Type | Name | Description |
|---|---|---|
| Stream | stream | The stream to load from. |
Returns
| Type | Description |
|---|---|
| Bitmap | The loaded bitmap. |
GetFrameCount(FrameDimension)
Returns the number of frames available in the specified animation dimension.
Declaration
public override int GetFrameCount(FrameDimension dimension)
Parameters
| Type | Name | Description |
|---|---|---|
| FrameDimension | dimension |
Returns
| Type | Description |
|---|---|
| int |
Overrides
GetHbitmap()
Returns a handle to this bitmap.
Declaration
public IntPtr GetHbitmap()
Returns
| Type | Description |
|---|---|
| IntPtr | A handle to the bitmap. |
Exceptions
| Type | Condition |
|---|---|
| PlatformNotSupportedException | This method is not supported on this platform. |
GetHbitmap(Color)
Returns a handle to this bitmap with the specified background color.
Declaration
public IntPtr GetHbitmap(Color background)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | background | The background color. |
Returns
| Type | Description |
|---|---|
| IntPtr | A handle to the bitmap. |
Exceptions
| Type | Condition |
|---|---|
| PlatformNotSupportedException | This method is not supported on this platform. |
GetPixel(int, int)
Gets the color of the pixel at the specified coordinates.
Declaration
public Color GetPixel(int x, int y)
Parameters
| Type | Name | Description |
|---|---|---|
| int | x | The x-coordinate of the pixel. |
| int | y | The y-coordinate of the pixel. |
Returns
| Type | Description |
|---|---|
| Color | The color of the pixel. |
LockBits(Rectangle, ImageLockMode, PixelFormat)
Locks a rectangular region of the bitmap for pixel access.
Declaration
public BitmapData LockBits(Rectangle rect, ImageLockMode flags, PixelFormat format)
Parameters
| Type | Name | Description |
|---|---|---|
| Rectangle | rect | The region to lock. |
| ImageLockMode | flags | The lock mode flags. |
| PixelFormat | format | The pixel format to use for the locked data. |
Returns
| Type | Description |
|---|---|
| BitmapData | The locked bitmap data. |
MakeTransparent()
Makes the default color transparent for this bitmap.
Declaration
public void MakeTransparent()
MakeTransparent(Color)
Makes the specified color transparent for this bitmap.
Declaration
public void MakeTransparent(Color transparentColor)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | transparentColor | The color to make transparent. |
RotateFlip(RotateFlipType)
Rotates and flips the bitmap.
Declaration
public override void RotateFlip(RotateFlipType rft)
Parameters
| Type | Name | Description |
|---|---|---|
| RotateFlipType | rft | The rotation and flip type. |
Overrides
Save(Stream, ImageFormat)
Saves this bitmap to the specified stream in the specified format.
Declaration
public override void Save(Stream stream, ImageFormat format)
Parameters
| Type | Name | Description |
|---|---|---|
| Stream | stream | The stream to save to. |
| ImageFormat | format | The format to save in. |
Overrides
Save(Stream, ImageFormat, EncoderParameters?)
Saves this bitmap to the specified stream in the specified format with encoder parameters.
Declaration
public override void Save(Stream stream, ImageFormat format, EncoderParameters? encoderParams)
Parameters
| Type | Name | Description |
|---|---|---|
| Stream | stream | The stream to save to. |
| ImageFormat | format | The format to save in. |
| EncoderParameters | encoderParams | The encoder parameters. |
Overrides
Save(string)
Saves this bitmap to the specified file.
Declaration
public override void Save(string filename)
Parameters
| Type | Name | Description |
|---|---|---|
| string | filename | The file name to save to. |
Overrides
Save(string, ImageFormat)
Saves this bitmap to the specified file in the specified format.
Declaration
public override void Save(string filename, ImageFormat format)
Parameters
| Type | Name | Description |
|---|---|---|
| string | filename | The file name to save to. |
| ImageFormat | format | The format to save in. |
Overrides
SelectActiveFrame(FrameDimension, int)
Selects the active frame in the specified animation dimension.
Declaration
public override int SelectActiveFrame(FrameDimension dimension, int idx)
Parameters
| Type | Name | Description |
|---|---|---|
| FrameDimension | dimension | |
| int | idx |
Returns
| Type | Description |
|---|---|
| int |
Overrides
SetPixel(int, int, Color)
Sets the color of the pixel at the specified coordinates.
Declaration
public void SetPixel(int x, int y, Color color)
Parameters
| Type | Name | Description |
|---|---|---|
| int | x | The x-coordinate of the pixel. |
| int | y | The y-coordinate of the pixel. |
| Color | color | The color to set. |
UnlockBits(BitmapData)
Unlocks a previously locked region of the bitmap.
Declaration
public void UnlockBits(BitmapData bitmapData)
Parameters
| Type | Name | Description |
|---|---|---|
| BitmapData | bitmapData | The locked bitmap data to unlock. |