Skip to main content

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.

public class Bitmap : Image

Constructors

Instance member Bitmap(image)

Initializes a new instance of the Bitmap class using an existing image.

NameTypeDescription
imageImageThe source image to create the bitmap from.

Instance member Bitmap(stream)

Initializes a new instance of the Bitmap class from a stream containing image data.

NameTypeDescription
streamStreamThe stream containing image data.

Instance member Bitmap(stream, useEmbeddedColorManagement)

Initializes a new instance of the Bitmap class from the specified data

NameTypeDescription
streamStreamThe stream containing image data.
useEmbeddedColorManagementBooleantrue to use color correction for this Bitmap; otherwise, false.

Instance member Bitmap(fileName)

Initializes a new instance of the Bitmap class from a file on disk.

NameTypeDescription
fileNameStringThe path to the image file.

Instance member Bitmap(fileName, useEmbeddedColorManagement)

Initializes a new instance of the Bitmap class from the specified data

NameTypeDescription
fileNameStringThe path to the image file.
useEmbeddedColorManagementBooleantrue to use color correction for this Bitmap; otherwise, false.

Instance member Bitmap(image, size)

Initializes a new instance of the Bitmap class with the specified size.

NameTypeDescription
imageImageThe source image to create the bitmap from.
sizeSizeThe size to which the image should be resized.

Instance member Bitmap(image, width, height)

Initializes a new instance of the Bitmap class with the specified width and height.

NameTypeDescription
imageImageThe source image to create the bitmap from.
widthInt32The width of the new bitmap.
heightInt32The height of the new bitmap.

Instance member Bitmap(type, resource)

Initializes a new instance of the Bitmap class from a resource in the specified assembly.

NameTypeDescription
typeTypeThe type in the assembly where the resource is located.
resourceStringThe name of the resource.

Instance member Bitmap(width, height)

Initializes a new instance of the Bitmap class with the specified size.

NameTypeDescription
widthInt32The width, in pixels.
heightInt32The height, in pixels.

Instance member Bitmap(width, height, format)

Initializes a new instance of the Bitmap class with the specified width and height, using the specified pixel format.

NameTypeDescription
widthInt32The width, in pixels.
heightInt32The height, in pixels.
formatPixelFormatThe pixel format of the new bitmap.

Methods

Instance member Clone(rect, format)

Creates a copy of the section of this Bitmap defined by with a specified PixelFormat.

ParameterTypeDescription
rectRectangleFDefines the portion of this Bitmap to copy. Coordinates are relative to this Bitmap.
formatPixelFormatThe pixel format for the new Bitmap. This must specify a value that begins with Format.

Returns: Bitmap. The new cloned bitmap.

Instance member Clone(rect, format)

Creates a copy of the section of this Bitmap defined by with a specified PixelFormat.

ParameterTypeDescription
rectRectangleDefines the portion of this Bitmap to copy. Coordinates are relative to this Bitmap.
formatPixelFormatThe pixel format for the new Bitmap. This must specify a value that begins with Format.

Returns: Bitmap. The new cloned bitmap.

Instance member GetPixel(x, y)

Returns the color of the specified pixel in this Bitmap.

ParameterTypeDescription
xInt32The x-coordinate of the pixel to get.
yInt32The y-coordinate of the pixel to get.

Returns: Color. A Color structure that represents the color of the specified pixel.

Instance member LockBits(rect, flags, format)

Locks a portion of the bitmap for direct pixel manipulation.

ParameterTypeDescription
rectRectangleThe region of the bitmap to lock.
flagsImageLockModeThe locking mode.
formatPixelFormatThe pixel format to use for the locked region.

Returns: BitmapData. A BitmapData object representing the locked region.

Instance member LockBits(rect, flags, format, bitmapData)

Locks a portion of the bitmap for direct pixel manipulation.

ParameterTypeDescription
rectRectangleThe region of the bitmap to lock.
flagsImageLockModeThe locking mode.
formatPixelFormatThe pixel format to use for the locked region.
bitmapDataBitmapDataA BitmapData that contains information about the lock operation.

Returns: BitmapData. A BitmapData object representing the locked region.

Instance member MakeGrayscale()

Converts the current image to grayscale in place, preserving the alpha channel.

Instance member MakeTransparent()

Makes the default transparent color, which is the pixels at the bottom left corner, transparent in the bitmap.

Instance member MakeTransparent(transparentColor)

Makes the specified color transparent in the bitmap.

ParameterTypeDescription
transparentColorColorThe color to make transparent.

Instance member SetPixel(x, y, color)

Sets the color of the specified pixel in this Bitmap.

ParameterTypeDescription
xInt32The x-coordinate of the pixel to set.
yInt32The y-coordinate of the pixel to set.
colorColorThe color to assign to the specified pixel.

Instance member SetResolution(xDpi, yDpi)

Sets the resolution for this Bitmap.

ParameterTypeDescription
xDpiSingleThe horizontal resolution, in dots per inch, of the Bitmap.
yDpiSingleThe vertical resolution, in dots per inch, of the Bitmap.

Instance member UnlockBits(bitmapData)

Unlocks the previously locked region of the bitmap.

ParameterTypeDescription
bitmapDataBitmapDataThe BitmapData object representing the locked region.