Graphics 如何使用Direct2D高效地将像素写入屏幕
我有一个像素数组(m_像素),我想使用Direct2D渲染到屏幕上。 该数组包含10000个元素(100行100像素)。下面的代码在像素上循环,并将它们作为10x10个矩形绘制到屏幕上。是否有更有效的方法执行此操作?如何向像素/图像添加高斯模糊效果Graphics 如何使用Direct2D高效地将像素写入屏幕,graphics,microsoft-metro,directx,direct2d,Graphics,Microsoft Metro,Directx,Direct2d,我有一个像素数组(m_像素),我想使用Direct2D渲染到屏幕上。 该数组包含10000个元素(100行100像素)。下面的代码在像素上循环,并将它们作为10x10个矩形绘制到屏幕上。是否有更有效的方法执行此操作?如何向像素/图像添加高斯模糊效果 m_d2dContext->BeginDraw(); m_d2dContext->Clear(ColorF(0.0f, 0.0f, 0.0f)); // Render m_pixels // m_pixels is updated
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();
m_d2dContext->BeginDraw();
m_d2dContext->Clear(ColorF(0.0f,0.0f,0.0f));
//渲染m_像素
//m_像素在渲染之前由解算器直接更新
auto rect=D2D1_rect_F();
ComPtr-pBlackBrush;
DX::ThrowIfFailed(m_d2dContext->CreateSolidColorBrush(ColorF(1.0f,0.0f,0.0f),&pBlackBrush));
对于(int i=0;iSetColor(D2D1::ColorF(m_像素[i]*3,m_像素[i],m_像素[i]);
//更新矩形大小
矩形顶部=10*层(i/100);
左直=10*层(i%100);
直底=10*层(i/100)+10;
右直=10*层(i%100)+10;
//设置矩形的颜色
m_d2dContext->FillRectangle(rect,pBlackBrush.Get());
}
HRESULT hr=m_d2dContext->EndDraw();
尝试使用ID2D1RenderTarget::CreateBitmap()
和ID2D1RenderTarget::DrawBitmap()
如何向像素/图像添加高斯模糊效果
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();
在Direct2D中,有(ID2D1Effect)用于简单的位图处理。您可以编写自己的[看起来比较复杂],也可以使用其中一个[相当简单]。其中之一是。是否尝试将数据填充到位图并渲染到屏幕上?GaussianBlur由一个过滤器内核描述,您可以在渲染之前将其应用于数组的每个元素。