Skip to content

Direct pixel access to D2DBitmap #110

@mystery123sk

Description

@mystery123sk

Hi, is there a way to directly change byte array of D2DBitmap as it's possible in C++ D2D? Something like this in C++:

// Assuming you have a valid ID2D1Bitmap* named bitmap
D2D1_BITMAP_PROPERTIES bitmapProperties;
bitmap->GetDpi(nullptr, nullptr);
bitmap->GetPixelFormat(&bitmapProperties.pixelFormat);

UINT32 width, height;
bitmap->GetSize(&width, &height);

UINT32 pixelSize = bitmapProperties.pixelFormat.GetPixelSize();
UINT32 stride = width * pixelSize;

D2D1_MAPPED_RECT mappedRect;
HRESULT hr = bitmap->Map(D2D1_MAP_OPTIONS_READ | D2D1_MAP_OPTIONS_WRITE, &mappedRect);
if (SUCCEEDED(hr))
{
    BYTE* pixelData = mappedRect.bits;
    // Now you can access and modify the pixel data here

    // Make sure to unmap the bitmap when you're done editing
    bitmap->Unmap();
}

It could help us improve the performance, since every time we call CreateBitmapFromMemory, a new bitmap is created in memory.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions