Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Direct pixel access to D2DBitmap #110

Open
mystery123sk opened this issue Jun 20, 2023 · 0 comments
Open

Direct pixel access to D2DBitmap #110

mystery123sk opened this issue Jun 20, 2023 · 0 comments

Comments

@mystery123sk
Copy link

mystery123sk commented Jun 20, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant