Bitmap

System.Drawing.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

Bitmap(image)

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

Name
Type
Description

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

The stream containing image data.

Bitmap(stream, useEmbeddedColorManagement)

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

Name
Type
Description

stream

The stream containing image data.

useEmbeddedColorManagement

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

The path to the image file.

Bitmap(image, size)

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

Name
Type
Description

image

The source image to create the bitmap from.

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

The source image to create the bitmap from.

width

The width of the new bitmap.

height

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

The type in the assembly where the resource is located.

resource

The name of the resource.

Bitmap(width, height)

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

Name
Type
Description

width

The width, in pixels.

height

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

The width, in pixels.

height

The height, in pixels.

format

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

Defines the portion of this Bitmap to copy. Coordinates are relative to this Bitmap.

format

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

Defines the portion of this Bitmap to copy. Coordinates are relative to this Bitmap.

format

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

The x-coordinate of the pixel to get.

y

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

The region of the bitmap to lock.

flags

The locking mode. Not used - kept for compatibility.

format

The pixel format to use for the locked region. Not used - kept for compatibility.

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

The region of the bitmap to lock.

flags

The locking mode. Not used - kept for compatibility.

format

The pixel format to use for the locked region. Not used - kept for compatibility.

bitmapData

A BitmapData that contains information about the lock operation.

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

The parameter flags is not used in this implementation and is present only for compatibility with the original GDI+ method signature. Locked bits are always locked for read and write access and can be manipulated directly via the Scan0 in parallel. Therefore there is no guarantee that the pixel data will remain unchanged during the lock period if other threads are accessing the bitmap.

Moreover the memory pointed by Scan0 is a copy of the original bitmap data. The bitmap is not modified until UnlockBits is called.

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

The color to make transparent.

SetPixel(x, y, color)

Sets the color of the specified pixel in this Bitmap.

Parameter
Type
Description

x

The x-coordinate of the pixel to set.

y

The y-coordinate of the pixel to set.

color

The color to assign to the specified pixel.

SetResolution(xDpi, yDpi)

Sets the resolution for this Bitmap.

Parameter
Type
Description

xDpi

The horizontal resolution, in dots per inch, of the Bitmap.

yDpi

The vertical resolution, in dots per inch, of the Bitmap.

UnlockBits(bitmapData)

Unlocks the previously locked region of the bitmap and updateds the bitmap with any changes made to the pixel data.

Parameter
Type
Description

bitmapData

The BitmapData object representing the locked region.

Last updated

Was this helpful?