How to efficiently write pixels to the screen with Direct2D

萝らか妹 提交于 2020-01-15 04:01:05

问题


I have a array of pixels (m_pixels) that I want to render to the screen using Direct2D. The array contains 10,000 elements (100 rows of 100 pixels). The code below loops over the pixels and draws them to the screen as 10x10 rectangles. Is there a more efficient way of performing this operation? How can I add a GaussianBlur effect to the pixels/image?

m_d2dContext->BeginDraw();
m_d2dContext->Clear(ColorF(0.0f, 0.0f, 0.0f));



// Render m_pixels
// m_pixels is updated by the solver directly before render
auto rect = D2D1_RECT_F();
ComPtr<ID2D1SolidColorBrush> pBlackBrush;
DX::ThrowIfFailed(m_d2dContext->CreateSolidColorBrush(ColorF(1.0f, 0.0f, 0.0f),&pBlackBrush));

for (int i=0; i<10000; i++){
    //Update the color
    pBlackBrush->SetColor(D2D1::ColorF(m_pixels[i]*3, m_pixels[i], m_pixels[i]));
    //Update the rectangle size
    rect.top = 10*floor(i/100);
    rect.left = 10*floor(i%100);
    rect.bottom = 10*floor(i/100) + 10;
    rect.right = 10*floor(i%100) + 10;
    //Set the rectangle color
    m_d2dContext->FillRectangle(rect, pBlackBrush.Get());
}

HRESULT hr = m_d2dContext->EndDraw();

回答1:


Try using ID2D1RenderTarget::CreateBitmap() and ID2D1RenderTarget::DrawBitmap()




回答2:


How can I add a GaussianBlur effect to the pixels/image?

In Direct2D there are effects (ID2D1Effect) for simple bitmap processing. You can write your own [it seems comparatively complicated], or use one of the built-in effects [which is rather simple]. One of them is Gaussian blur.



来源:https://stackoverflow.com/questions/13814610/how-to-efficiently-write-pixels-to-the-screen-with-direct2d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!