Syntax
HRESULT CreateBitmap(D2D1_SIZE_U size, const void *srcData, UINT32 pitch, const D2D1_BITMAP_PROPERTIES &bitmapProperties, ID2D1Bitmap **bitmap);
Creates a bitmap that is compatible with this render target.
Return Value
If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
Example
The following example creates a bitmap from raw pixel data. This is a simplified example and might require adjustments based on your specific pixel format and data layout.
// Assume pRenderTarget is a valid ID2D1RenderTarget*
// Assume pFactory is a valid ID2D1Factory*
UINT32 width = 100;
UINT32 height = 50;
UINT32 pitch = width * sizeof(D2D1_COLOR_F); // Assuming RGBA floats
// Simple RGBA color data (e.g., all red)
std::vector<D2D1_COLOR_F> pixelData(width * height, D2D1_COLOR_F{1.0f, 0.0f, 0.0f, 1.0f});
D2D1_BITMAP_PROPERTIES bitmapProperties = D2D1::BitmapProperties(
D2D1::PixelFormat(DXGI_FORMAT_R32G32B32A32_FLOAT, D2D1_ALPHA_MODE_PREMULTIPLIED)
);
ID2D1Bitmap *pBitmap = nullptr;
HRESULT hr = pRenderTarget->CreateBitmap(
D2D1::SizeU(width, height),
pixelData.data(),
pitch,
bitmapProperties,
&pBitmap
);
if (SUCCEEDED(hr))
{
// Use the pBitmap here, e.g., draw it to the render target
// pRenderTarget->DrawBitmap(pBitmap);
// Remember to release pBitmap when done
// pBitmap->Release();
}