Table of Contents

Class Bitmap

Namespace
SharpDX.Direct2D1
Assembly
SharpDX.Direct2D1.dll
[Guid("a2296057-ea42-4099-983b-539fb6505426")]
public class Bitmap : Image
Inheritance
Bitmap
Derived
Inherited Members

Constructors

Bitmap(RenderTarget, Surface)

Creates an Bitmap whose data is shared with another resource.

public Bitmap(RenderTarget renderTarget, Surface surface)

Parameters

renderTarget RenderTarget

an instance of RenderTarget

surface Surface

An SharpDX.DXGI.Surface that contains the data to share with the new ID2D1Bitmap. For more information, see the Remarks section.

Bitmap(RenderTarget, Surface, BitmapProperties?)

Creates an Bitmap whose data is shared with another resource.

public Bitmap(RenderTarget renderTarget, Surface surface, BitmapProperties? bitmapProperties)

Parameters

renderTarget RenderTarget

an instance of RenderTarget

surface Surface

An SharpDX.DXGI.Surface that contains the data to share with the new ID2D1Bitmap. For more information, see the Remarks section.

bitmapProperties BitmapProperties?

The pixel format and DPI of the bitmap to create . The SharpDX.DXGI.Format portion of the pixel format must match the SharpDX.DXGI.Format of data or the method will fail, but the alpha modes don't have to match. To prevent a mismatch, you can pass NULL or the value obtained from the {{D2D1::PixelFormat}} helper function. The DPI settings do not have to match those of data. If both dpiX and dpiY are 0.0f, the default DPI, 96, is used.

Bitmap(RenderTarget, Bitmap)

Creates an Bitmap whose data is shared with another resource.

public Bitmap(RenderTarget renderTarget, Bitmap bitmap)

Parameters

renderTarget RenderTarget

an instance of RenderTarget

bitmap Bitmap

An Bitmap that contains the data to share with the new ID2D1Bitmap. For more information, see the Remarks section.

Bitmap(RenderTarget, Bitmap, BitmapProperties?)

Creates an Bitmap whose data is shared with another resource.

public Bitmap(RenderTarget renderTarget, Bitmap bitmap, BitmapProperties? bitmapProperties)

Parameters

renderTarget RenderTarget

an instance of RenderTarget

bitmap Bitmap

An Bitmap that contains the data to share with the new ID2D1Bitmap. For more information, see the Remarks section.

bitmapProperties BitmapProperties?

The pixel format and DPI of the bitmap to create . The SharpDX.DXGI.Format portion of the pixel format must match the SharpDX.DXGI.Format of data or the method will fail, but the alpha modes don't have to match. To prevent a mismatch, you can pass NULL or the value obtained from the {{D2D1::PixelFormat}} helper function. The DPI settings do not have to match those of data. If both dpiX and dpiY are 0.0f, the default DPI, 96, is used.

Bitmap(RenderTarget, Size2)

Creates a Direct2D bitmap from a pointer to in-memory source data.

public Bitmap(RenderTarget renderTarget, Size2 size)

Parameters

renderTarget RenderTarget

an instance of RenderTarget

size Size2

The dimension of the bitmap to create in pixels.

Bitmap(RenderTarget, Size2, DataPointer, int)

Creates a Direct2D bitmap from a pointer to in-memory source data.

public Bitmap(RenderTarget renderTarget, Size2 size, DataPointer dataPointer, int pitch)

Parameters

renderTarget RenderTarget

an instance of RenderTarget

size Size2

The dimension of the bitmap to create in pixels.

dataPointer DataPointer

A pointer to the memory location of the image data, or NULL to create an uninitialized bitmap.

pitch int

The byte count of each scanline, which is equal to (the image width in pixels * the number of bytes per pixel) + memory padding. If srcData is NULL, this value is ignored. (Note that pitch is also sometimes called stride.)

Bitmap(RenderTarget, Size2, DataPointer, int, BitmapProperties)

Creates a Direct2D bitmap from a pointer to in-memory source data.

public Bitmap(RenderTarget renderTarget, Size2 size, DataPointer dataPointer, int pitch, BitmapProperties bitmapProperties)

Parameters

renderTarget RenderTarget

an instance of RenderTarget

size Size2

The dimension of the bitmap to create in pixels.

dataPointer DataPointer

A pointer to the memory location of the image data, or NULL to create an uninitialized bitmap.

pitch int

The byte count of each scanline, which is equal to (the image width in pixels * the number of bytes per pixel) + memory padding. If srcData is NULL, this value is ignored. (Note that pitch is also sometimes called stride.)

bitmapProperties BitmapProperties

The pixel format and dots per inch (DPI) of the bitmap to create.

Bitmap(RenderTarget, Size2, BitmapProperties)

Creates a Direct2D bitmap from a pointer to in-memory source data.

public Bitmap(RenderTarget renderTarget, Size2 size, BitmapProperties bitmapProperties)

Parameters

renderTarget RenderTarget

an instance of RenderTarget

size Size2

The dimension of the bitmap to create in pixels.

bitmapProperties BitmapProperties

The pixel format and dots per inch (DPI) of the bitmap to create.

Bitmap(RenderTarget, BitmapLock)

Creates an Bitmap that points to the bitmap data already stored in the BitmapLock.

public Bitmap(RenderTarget renderTarget, BitmapLock bitmapLock)

Parameters

renderTarget RenderTarget

An instance of RenderTarget.

bitmapLock BitmapLock

An RenderTarget that contains the data to share with the new Bitmap.

Bitmap(RenderTarget, BitmapLock, BitmapProperties?)

Creates an Bitmap that points to the bitmap data already stored in the BitmapLock.

public Bitmap(RenderTarget renderTarget, BitmapLock bitmapLock, BitmapProperties? bitmapProperties)

Parameters

renderTarget RenderTarget

An instance of RenderTarget.

bitmapLock BitmapLock

An RenderTarget that contains the data to share with the new Bitmap.

bitmapProperties BitmapProperties?

The pixel format and DPI of the bitmap to create . The SharpDX.DXGI.Format portion of the pixel format must match the SharpDX.DXGI.Format of data or the method will fail, but the alpha modes don't have to match. To prevent a mismatch, you can pass NULL or the value obtained from the {{D2D1::PixelFormat}} helper function. The DPI settings do not have to match those of data. If both dpiX and dpiY are 0.0f, the default DPI, 96, is used.

Bitmap(nint)

public Bitmap(nint nativePtr)

Parameters

nativePtr nint

Properties

DotsPerInch

Return the dots per inch (DPI) of the bitmap.

public Size2F DotsPerInch { get; }

Property Value

Size2F

The dots per inch (DPI) of the bitmap.

PixelFormat

Retrieves the pixel format and alpha mode of the bitmap.

public PixelFormat PixelFormat { get; }

Property Value

PixelFormat

PixelSize

Returns the size, in device-dependent units (pixels), of the bitmap.

public Size2 PixelSize { get; }

Property Value

Size2

Size

Returns the size, in device-independent pixels (DIPs), of the bitmap.

public Size2F Size { get; }

Property Value

Size2F

Remarks

A DIP is 1/96?of an inch. To retrieve the size in device pixels, use the ID2D1Bitmap::GetPixelSize method.

Methods

CopyFromBitmap(Bitmap)

Copies the specified region from the specified bitmap into the current bitmap.

public void CopyFromBitmap(Bitmap sourceBitmap)

Parameters

sourceBitmap Bitmap

The bitmap to copy from.

Remarks

This method does not update the size of the current bitmap. If the contents of the source bitmap do not fit in the current bitmap, this method fails. Also, note that this method does not perform format conversion, and will fail if the bitmap formats do not match. Calling this method may cause the current batch to flush if the bitmap is active in the batch. If the batch that was flushed does not complete successfully, this method fails. However, this method does not clear the error state of the render target on which the batch was flushed. The failing int and tag state will be returned at the next call to {{EndDraw}} or {{Flush}}.

CopyFromBitmap(Bitmap, RawPoint)

Copies the specified region from the specified bitmap into the current bitmap.

public void CopyFromBitmap(Bitmap sourceBitmap, RawPoint destinationPoint)

Parameters

sourceBitmap Bitmap

The bitmap to copy from.

destinationPoint RawPoint

In the current bitmap, the upper-left corner of the area to which the region specified by srcRect is copied.

Remarks

This method does not update the size of the current bitmap. If the contents of the source bitmap do not fit in the current bitmap, this method fails. Also, note that this method does not perform format conversion, and will fail if the bitmap formats do not match. Calling this method may cause the current batch to flush if the bitmap is active in the batch. If the batch that was flushed does not complete successfully, this method fails. However, this method does not clear the error state of the render target on which the batch was flushed. The failing int and tag state will be returned at the next call to {{EndDraw}} or {{Flush}}.

CopyFromBitmap(Bitmap, RawPoint, RawRectangle)

Copies the specified region from the specified bitmap into the current bitmap.

public void CopyFromBitmap(Bitmap sourceBitmap, RawPoint destinationPoint, RawRectangle sourceArea)

Parameters

sourceBitmap Bitmap

The bitmap to copy from.

destinationPoint RawPoint

In the current bitmap, the upper-left corner of the area to which the region specified by srcRect is copied.

sourceArea RawRectangle

The area of bitmap to copy.

Remarks

This method does not update the size of the current bitmap. If the contents of the source bitmap do not fit in the current bitmap, this method fails. Also, note that this method does not perform format conversion, and will fail if the bitmap formats do not match. Calling this method may cause the current batch to flush if the bitmap is active in the batch. If the batch that was flushed does not complete successfully, this method fails. However, this method does not clear the error state of the render target on which the batch was flushed. The failing int and tag state will be returned at the next call to {{EndDraw}} or {{Flush}}.

CopyFromMemory(byte[], int)

Copies the specified region from memory into the current bitmap.

public void CopyFromMemory(byte[] memory, int pitch)

Parameters

memory byte[]

The data to copy.

pitch int

The stride, or pitch, of the source bitmap stored in srcData. The stride is the byte count of a scanline (one row of pixels in memory). The stride can be computed from the following formula: pixel width * bytes per pixel + memory padding.

Remarks

This method does not update the size of the current bitmap. If the contents of the source bitmap do not fit in the current bitmap, this method fails. Also, note that this method does not perform format conversion; the two bitmap formats should match. Passing this method invalid input, such as an invalid destination rectangle, can produce unpredictable results, such as a distorted image or device failure. Calling this method may cause the current batch to flush if the bitmap is active in the batch. If the batch that was flushed does not complete successfully, this method fails. However, this method does not clear the error state of the render target on which the batch was flushed. The failing int and tag state will be returned at the next call to {{EndDraw}} or {{Flush}}.

CopyFromMemory(byte[], int, RawRectangle)

Copies the specified region from memory into the current bitmap.

public void CopyFromMemory(byte[] memory, int pitch, RawRectangle destinationArea)

Parameters

memory byte[]

The data to copy.

pitch int

The stride, or pitch, of the source bitmap stored in srcData. The stride is the byte count of a scanline (one row of pixels in memory). The stride can be computed from the following formula: pixel width * bytes per pixel + memory padding.

destinationArea RawRectangle

In the current bitmap, the upper-left corner of the area to which the region specified by srcRect is copied.

Remarks

This method does not update the size of the current bitmap. If the contents of the source bitmap do not fit in the current bitmap, this method fails. Also, note that this method does not perform format conversion; the two bitmap formats should match. Passing this method invalid input, such as an invalid destination rectangle, can produce unpredictable results, such as a distorted image or device failure. Calling this method may cause the current batch to flush if the bitmap is active in the batch. If the batch that was flushed does not complete successfully, this method fails. However, this method does not clear the error state of the render target on which the batch was flushed. The failing int and tag state will be returned at the next call to {{EndDraw}} or {{Flush}}.

CopyFromMemory(nint, int)

Copies the specified region from memory into the current bitmap.

public void CopyFromMemory(nint pointer, int pitch)

Parameters

pointer nint

The data to copy.

pitch int

The stride, or pitch, of the source bitmap stored in srcData. The stride is the byte count of a scanline (one row of pixels in memory). The stride can be computed from the following formula: pixel width * bytes per pixel + memory padding.

Remarks

This method does not update the size of the current bitmap. If the contents of the source bitmap do not fit in the current bitmap, this method fails. Also, note that this method does not perform format conversion; the two bitmap formats should match. Passing this method invalid input, such as an invalid destination rectangle, can produce unpredictable results, such as a distorted image or device failure. Calling this method may cause the current batch to flush if the bitmap is active in the batch. If the batch that was flushed does not complete successfully, this method fails. However, this method does not clear the error state of the render target on which the batch was flushed. The failing int and tag state will be returned at the next call to {{EndDraw}} or {{Flush}}.

CopyFromMemory(nint, int, RawRectangle)

Copies the specified region from memory into the current bitmap.

public void CopyFromMemory(nint pointer, int pitch, RawRectangle destinationArea)

Parameters

pointer nint

The data to copy.

pitch int

The stride, or pitch, of the source bitmap stored in srcData. The stride is the byte count of a scanline (one row of pixels in memory). The stride can be computed from the following formula: pixel width * bytes per pixel + memory padding.

destinationArea RawRectangle

In the current bitmap, the upper-left corner of the area to which the region specified by srcRect is copied.

Remarks

This method does not update the size of the current bitmap. If the contents of the source bitmap do not fit in the current bitmap, this method fails. Also, note that this method does not perform format conversion; the two bitmap formats should match. Passing this method invalid input, such as an invalid destination rectangle, can produce unpredictable results, such as a distorted image or device failure. Calling this method may cause the current batch to flush if the bitmap is active in the batch. If the batch that was flushed does not complete successfully, this method fails. However, this method does not clear the error state of the render target on which the batch was flushed. The failing int and tag state will be returned at the next call to {{EndDraw}} or {{Flush}}.

CopyFromMemory<T>(T[], int)

Copies the specified region from memory into the current bitmap.

public void CopyFromMemory<T>(T[] memory, int pitch = 0) where T : struct

Parameters

memory T[]

The data to copy.

pitch int

The stride, or pitch, of the source bitmap stored in srcData. The stride is the byte count of a scanline (one row of pixels in memory). The stride can be computed from the following formula: pixel width * bytes per pixel + memory padding.

Type Parameters

T

Remarks

This method does not update the size of the current bitmap. If the contents of the source bitmap do not fit in the current bitmap, this method fails. Also, note that this method does not perform format conversion; the two bitmap formats should match. Passing this method invalid input, such as an invalid destination rectangle, can produce unpredictable results, such as a distorted image or device failure. Calling this method may cause the current batch to flush if the bitmap is active in the batch. If the batch that was flushed does not complete successfully, this method fails. However, this method does not clear the error state of the render target on which the batch was flushed. The failing int and tag state will be returned at the next call to {{EndDraw}} or {{Flush}}.

CopyFromMemory<T>(T[], int, RawRectangle)

Copies the specified region from memory into the current bitmap.

public void CopyFromMemory<T>(T[] memory, int pitch, RawRectangle destinationArea) where T : struct

Parameters

memory T[]

The data to copy.

pitch int

The stride, or pitch, of the source bitmap stored in srcData. The stride is the byte count of a scanline (one row of pixels in memory). The stride can be computed from the following formula: pixel width * bytes per pixel + memory padding.

destinationArea RawRectangle

In the current bitmap, the upper-left corner of the area to which the region specified by srcRect is copied.

Type Parameters

T

Remarks

This method does not update the size of the current bitmap. If the contents of the source bitmap do not fit in the current bitmap, this method fails. Also, note that this method does not perform format conversion; the two bitmap formats should match. Passing this method invalid input, such as an invalid destination rectangle, can produce unpredictable results, such as a distorted image or device failure. Calling this method may cause the current batch to flush if the bitmap is active in the batch. If the batch that was flushed does not complete successfully, this method fails. However, this method does not clear the error state of the render target on which the batch was flushed. The failing int and tag state will be returned at the next call to {{EndDraw}} or {{Flush}}.

CopyFromRenderTarget(RenderTarget)

Copies the specified region from the specified render target into the current bitmap.

public void CopyFromRenderTarget(RenderTarget renderTarget)

Parameters

renderTarget RenderTarget

The render target that contains the region to copy.

Remarks

This method does not update the size of the current bitmap. If the contents of the source bitmap do not fit in the current bitmap, this method fails. Also, note that this method does not perform format conversion, and will fail if the bitmap formats do not match. Calling this method may cause the current batch to flush if the bitmap is active in the batch. If the batch that was flushed does not complete successfully, this method fails. However, this method does not clear the error state of the render target on which the batch was flushed. The failing int and tag state will be returned at the next call to {{EndDraw}} or {{Flush}}. All clips and layers must be popped off of the render target before calling this method. The method returns {{D2DERR_RENDER_TARGET_HAS_LAYER_OR_CLIPRECT}} if any clips or layers are currently applied to the render target.

CopyFromRenderTarget(RenderTarget, RawPoint)

Copies the specified region from the specified render target into the current bitmap.

public void CopyFromRenderTarget(RenderTarget renderTarget, RawPoint destinationPoint)

Parameters

renderTarget RenderTarget

The render target that contains the region to copy.

destinationPoint RawPoint

In the current bitmap, the upper-left corner of the area to which the region specified by srcRect is copied.

Remarks

This method does not update the size of the current bitmap. If the contents of the source bitmap do not fit in the current bitmap, this method fails. Also, note that this method does not perform format conversion, and will fail if the bitmap formats do not match. Calling this method may cause the current batch to flush if the bitmap is active in the batch. If the batch that was flushed does not complete successfully, this method fails. However, this method does not clear the error state of the render target on which the batch was flushed. The failing int and tag state will be returned at the next call to {{EndDraw}} or {{Flush}}. All clips and layers must be popped off of the render target before calling this method. The method returns {{D2DERR_RENDER_TARGET_HAS_LAYER_OR_CLIPRECT}} if any clips or layers are currently applied to the render target.

CopyFromRenderTarget(RenderTarget, RawPoint, RawRectangle)

Copies the specified region from the specified render target into the current bitmap.

public void CopyFromRenderTarget(RenderTarget renderTarget, RawPoint destinationPoint, RawRectangle sourceArea)

Parameters

renderTarget RenderTarget

The render target that contains the region to copy.

destinationPoint RawPoint

In the current bitmap, the upper-left corner of the area to which the region specified by srcRect is copied.

sourceArea RawRectangle

The area of renderTarget to copy.

Remarks

This method does not update the size of the current bitmap. If the contents of the source bitmap do not fit in the current bitmap, this method fails. Also, note that this method does not perform format conversion, and will fail if the bitmap formats do not match. Calling this method may cause the current batch to flush if the bitmap is active in the batch. If the batch that was flushed does not complete successfully, this method fails. However, this method does not clear the error state of the render target on which the batch was flushed. The failing int and tag state will be returned at the next call to {{EndDraw}} or {{Flush}}. All clips and layers must be popped off of the render target before calling this method. The method returns {{D2DERR_RENDER_TARGET_HAS_LAYER_OR_CLIPRECT}} if any clips or layers are currently applied to the render target.

CopyFromStream(Stream, int, int)

Copies the specified region from a stream into the current bitmap.

public void CopyFromStream(Stream stream, int pitch, int length)

Parameters

stream Stream

The stream to copy the data from.

pitch int

The stride, or pitch, of the source bitmap stored in srcData. The stride is the byte count of a scanline (one row of pixels in memory). The stride can be computed from the following formula: pixel width * bytes per pixel + memory padding.

length int

Length in bytes of the data to copy from the stream.

Remarks

This method does not update the size of the current bitmap. If the contents of the source bitmap do not fit in the current bitmap, this method fails. Also, note that this method does not perform format conversion; the two bitmap formats should match. Passing this method invalid input, such as an invalid destination rectangle, can produce unpredictable results, such as a distorted image or device failure. Calling this method may cause the current batch to flush if the bitmap is active in the batch. If the batch that was flushed does not complete successfully, this method fails. However, this method does not clear the error state of the render target on which the batch was flushed. The failing int and tag state will be returned at the next call to {{EndDraw}} or {{Flush}}.

CopyFromStream(Stream, int, int, RawRectangle)

Copies the specified region from a stream into the current bitmap.

public void CopyFromStream(Stream stream, int pitch, int length, RawRectangle destinationArea)

Parameters

stream Stream

The stream to copy the data from.

pitch int

The stride, or pitch, of the source bitmap stored in srcData. The stride is the byte count of a scanline (one row of pixels in memory). The stride can be computed from the following formula: pixel width * bytes per pixel + memory padding.

length int

Length in bytes of the data to copy from the stream.

destinationArea RawRectangle

In the current bitmap, the upper-left corner of the area to which the region specified by srcRect is copied.

Remarks

This method does not update the size of the current bitmap. If the contents of the source bitmap do not fit in the current bitmap, this method fails. Also, note that this method does not perform format conversion; the two bitmap formats should match. Passing this method invalid input, such as an invalid destination rectangle, can produce unpredictable results, such as a distorted image or device failure. Calling this method may cause the current batch to flush if the bitmap is active in the batch. If the batch that was flushed does not complete successfully, this method fails. However, this method does not clear the error state of the render target on which the batch was flushed. The failing int and tag state will be returned at the next call to {{EndDraw}} or {{Flush}}.

FromWicBitmap(RenderTarget, BitmapSource)

Creates a Bitmap from a WIC bitmap.

public static Bitmap FromWicBitmap(RenderTarget renderTarget, BitmapSource wicBitmapSource)

Parameters

renderTarget RenderTarget

The render target.

wicBitmapSource BitmapSource

A reference to a BitmapSource WIC bitmap.

Returns

Bitmap

FromWicBitmap(RenderTarget, BitmapSource, BitmapProperties)

Creates a Bitmap from a WIC bitmap.

public static Bitmap FromWicBitmap(RenderTarget renderTarget, BitmapSource wicBitmap, BitmapProperties bitmapProperties)

Parameters

renderTarget RenderTarget

The render target.

wicBitmap BitmapSource

The WIC bitmap.

bitmapProperties BitmapProperties

The bitmap properties.

Returns

Bitmap

New<T>(RenderTarget, Size2, T[], BitmapProperties)

Creates a Direct2D bitmap from a pointer to in-memory source data.

public static Bitmap New<T>(RenderTarget renderTarget, Size2 size, T[] pixelDatas, BitmapProperties bitmapProperties) where T : struct

Parameters

renderTarget RenderTarget

an instance of RenderTarget

size Size2

The dimension of the bitmap to create in pixels.

pixelDatas T[]

A pointer to an array of pixel data. The size of the array must be equal to sizeof(pixel) * Size.Width * Height.

bitmapProperties BitmapProperties

The pixel format and dots per inch (DPI) of the bitmap to create.

Returns

Bitmap

Type Parameters

T

Operators

explicit operator Bitmap(nint)

public static explicit operator Bitmap(nint nativePtr)

Parameters

nativePtr nint

Returns

Bitmap