我有一个像素数组 (m_pixels),我想使用 Direct2D 将其渲染到屏幕上。该数组包含 10,000 个元素(100 行,每行 100 个像素)。下面的代码循环遍历像素并将它们作为 10x10 矩形绘制到屏幕上。有没有更有效的方法来执行这个操作?如何为像素/图像添加高斯模糊效果?
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();