Direct2D Documentation

Bitmaps in Direct2D

A bitmap in Direct2D represents pixel data that can be used as a source for drawing operations. Bitmaps enable you to render images, create custom textures, and perform off‑screen rendering.

Key Concepts

Creating a Bitmap

HRESULT CreateBitmap(
    ID2D1RenderTarget *renderTarget,
    const D2D1_SIZE_U &size,
    const D2D1_BITMAP_PROPERTIES &props,
    ID2D1Bitmap **bitmap)
{
    return renderTarget->CreateBitmap(size, nullptr, 0, &props, bitmap);
}

Bitmap Properties Structure

D2D1_BITMAP_PROPERTIES props = D2D1::BitmapProperties(
    D2D1::PixelFormat(
        DXGI_FORMAT_B8G8R8A8_UNORM,
        D2D1_ALPHA_MODE_PREMULTIPLIED),
    96.0f,   // DPI X
    96.0f    // DPI Y
);

Common Use Cases

ScenarioMethodNotes
Loading from fileIWICImagingFactory + CreateBitmapFromWicBitmapSupports PNG, JPEG, GIF, etc.
Off‑screen renderingRenderTarget::CreateCompatibleRenderTargetUse bitmap as the target.
Dynamic texturesBitmap::CopyFromMemoryUpdate pixel data each frame.
Interoperability with Direct3DDXGI Surface + ID2D1Bitmap1Share resources across APIs.

Performance Tips

See Also