我有一个像素数组 (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();
尝试使用ID2D1RenderTarget::CreateBitmap()
and ID2D1RenderTarget::DrawBitmap()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)