The ID2D1Bitmap1 interface represents a bitmap that can be used as a drawing target or as a brush source. It extends ID2D1Bitmap with added capabilities for color space and DPI support.
ID2D1Resource → ID2D1Image → ID2D1Bitmap → ID2D1Bitmap1
interface ID2D1Bitmap1 : ID2D1Bitmap
{
HRESULT GetColorContext(ID2D1ColorContext **colorContext);
HRESULT GetBitmapProperties1(D2D1_BITMAP_PROPERTIES1 *bitmapProperties);
HRESULT GetSurface(IDXGISurface **dxgiSurface);
};
| Method | Return Type | Description |
|---|---|---|
GetColorContext |
HRESULT | Retrieves the ID2D1ColorContext describing the bitmap's color space. |
GetBitmapProperties1 |
HRESULT | Obtains extended bitmap properties, including DPI, pixel format, and color space. |
GetSurface |
HRESULT | Returns the underlying DXGI surface used for Direct3D interop. |
CopyFromBitmap (inherited) |
HRESULT | Copies pixel data from another bitmap. |
CopyFromRenderTarget (inherited) |
HRESULT | Copies data from a render target. |
All methods of ID2D1Bitmap1 are thread-safe provided the parent ID2D1DeviceContext is not being accessed concurrently.
// Assume d2dDeviceContext is a valid ID2D1DeviceContext *
ComPtr<ID2D1Bitmap1> bitmap;
D2D1_BITMAP_PROPERTIES1 bitmapProps = {};
bitmapProps.pixelFormat = D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM,
D2D1_ALPHA_MODE_PREMULTIPLIED);
bitmapProps.dpiX = 300.0f; // Custom DPI
bitmapProps.dpiY = 300.0f;
bitmapProps.bitmapOptions = D2D1_BITMAP_OPTIONS_NONE;
bitmapProps.colorContext = nullptr; // Use default sRGB
HRESULT hr = d2dDeviceContext->CreateBitmap(
D2D1::SizeU(1024, 768),
nullptr,
0,
&bitmapProps,
&bitmap);
if (SUCCEEDED(hr))
{
// Bitmap ready for high‑resolution rendering
}