Microsoft Docs

Direct2D API Reference

ID2D1Bitmap1 Interface

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.

Overview
Syntax
Methods
Remarks
Example

Inheritance

ID2D1ResourceID2D1ImageID2D1BitmapID2D1Bitmap1

Supported Interfaces

interface ID2D1Bitmap1 : ID2D1Bitmap
{
    HRESULT GetColorContext(ID2D1ColorContext **colorContext);
    HRESULT GetBitmapProperties1(D2D1_BITMAP_PROPERTIES1 *bitmapProperties);
    HRESULT GetSurface(IDXGISurface **dxgiSurface);
};
MethodReturn TypeDescription
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.

Thread Safety

All methods of ID2D1Bitmap1 are thread-safe provided the parent ID2D1DeviceContext is not being accessed concurrently.

Version Requirements

Creating a Bitmap with Custom DPI

// 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
}