Bitmap
Namespace: System.Drawing
Assembly: System.Drawing.Managed (4.0.0.0)
Encapsulates a bitmap, which consists of the pixel data for a graphics image and its attributes.
- C#
- VB.NET
public class Bitmap : Image
Public Class Bitmap
Inherits Image
Constructors
Bitmap(image)
Initializes a new instance of the Bitmap class using an existing image.
| Name | Type | Description |
|---|---|---|
| image | Image | The source image to create the bitmap from. |
Bitmap(stream)
Initializes a new instance of the Bitmap class from a stream containing image data.
| Name | Type | Description |
|---|---|---|
| stream | Stream | The stream containing image data. |
Bitmap(stream, useEmbeddedColorManagement)
Initializes a new instance of the Bitmap class from the specified data
| Name | Type | Description |
|---|---|---|
| stream | Stream | The stream containing image data. |
| useEmbeddedColorManagement | Boolean | true to use color correction for this Bitmap; otherwise, false. |
Bitmap(fileName)
Initializes a new instance of the Bitmap class from a file on disk.
| Name | Type | Description |
|---|---|---|
| fileName | String | The path to the image file. |
Bitmap(fileName, useEmbeddedColorManagement)
Initializes a new instance of the Bitmap class from the specified data
| Name | Type | Description |
|---|---|---|
| fileName | String | The path to the image file. |
| useEmbeddedColorManagement | Boolean | true to use color correction for this Bitmap; otherwise, false. |
Bitmap(image, size)
Initializes a new instance of the Bitmap class with the specified size.
| Name | Type | Description |
|---|---|---|
| image | Image | The source image to create the bitmap from. |
| size | Size | The size to which the image should be resized. |
Bitmap(image, width, height)
Initializes a new instance of the Bitmap class with the specified width and height.
| Name | Type | Description |
|---|---|---|
| image | Image | The source image to create the bitmap from. |
| width | Int32 | The width of the new bitmap. |
| height | Int32 | The height of the new bitmap. |
Bitmap(type, resource)
Initializes a new instance of the Bitmap class from a resource in the specified assembly.
| Name | Type | Description |
|---|---|---|
| type | Type | The type in the assembly where the resource is located. |
| resource | String | The name of the resource. |
Bitmap(width, height)
Initializes a new instance of the Bitmap class with the specified size.
| Name | Type | Description |
|---|---|---|
| width | Int32 | The width, in pixels. |
| height | Int32 | The height, in pixels. |
Bitmap(width, height, format)
Initializes a new instance of the Bitmap class with the specified width and height, using the specified pixel format.
| Name | Type | Description |
|---|---|---|
| width | Int32 | The width, in pixels. |
| height | Int32 | The height, in pixels. |
| format | PixelFormat | The pixel format of the new bitmap. |
Methods
Clone(rect, format)
Creates a copy of the section of this Bitmap defined by with a specified PixelFormat.
| Parameter | Type | Description |
|---|---|---|
| rect | RectangleF | Defines the portion of this Bitmap to copy. Coordinates are relative to this Bitmap. |
| format | PixelFormat | The pixel format for the new Bitmap. This must specify a value that begins with Format. |
Returns: Bitmap. The new cloned bitmap.
Clone(rect, format)
Creates a copy of the section of this Bitmap defined by with a specified PixelFormat.
| Parameter | Type | Description |
|---|---|---|
| rect | Rectangle | Defines the portion of this Bitmap to copy. Coordinates are relative to this Bitmap. |
| format | PixelFormat | The pixel format for the new Bitmap. This must specify a value that begins with Format. |
Returns: Bitmap. The new cloned bitmap.
GetPixel(x, y)
Returns the color of the specified pixel in this Bitmap.
| Parameter | Type | Description |
|---|---|---|
| x | Int32 | The x-coordinate of the pixel to get. |
| y | Int32 | The y-coordinate of the pixel to get. |
Returns: Color. A Color structure that represents the color of the specified pixel.
LockBits(rect, flags, format)
Locks a portion of the bitmap for direct pixel manipulation.
| Parameter | Type | Description |
|---|---|---|
| rect | Rectangle | The region of the bitmap to lock. |
| flags | ImageLockMode | The locking mode. |
| format | PixelFormat | The pixel format to use for the locked region. |
Returns: BitmapData. A BitmapData object representing the locked region.
LockBits(rect, flags, format, bitmapData)
Locks a portion of the bitmap for direct pixel manipulation.
| Parameter | Type | Description |
|---|---|---|
| rect | Rectangle | The region of the bitmap to lock. |
| flags | ImageLockMode | The locking mode. |
| format | PixelFormat | The pixel format to use for the locked region. |
| bitmapData | BitmapData | A BitmapData that contains information about the lock operation. |
Returns: BitmapData. A BitmapData object representing the locked region.
MakeGrayscale()
Converts the current image to grayscale in place, preserving the alpha channel.
MakeTransparent()
Makes the default transparent color, which is the pixels at the bottom left corner, transparent in the bitmap.
MakeTransparent(transparentColor)
Makes the specified color transparent in the bitmap.
| Parameter | Type | Description |
|---|---|---|
| transparentColor | Color | The color to make transparent. |
SetPixel(x, y, color)
Sets the color of the specified pixel in this Bitmap.
| Parameter | Type | Description |
|---|---|---|
| x | Int32 | The x-coordinate of the pixel to set. |
| y | Int32 | The y-coordinate of the pixel to set. |
| color | Color | The color to assign to the specified pixel. |
SetResolution(xDpi, yDpi)
Sets the resolution for this Bitmap.
| Parameter | Type | Description |
|---|---|---|
| xDpi | Single | The horizontal resolution, in dots per inch, of the Bitmap. |
| yDpi | Single | The vertical resolution, in dots per inch, of the Bitmap. |
UnlockBits(bitmapData)
Unlocks the previously locked region of the bitmap.
| Parameter | Type | Description |
|---|---|---|
| bitmapData | BitmapData | The BitmapData object representing the locked region. |