【问题标题】:How to efficiently write pixels to the screen with Direct2D如何使用 Direct2D 有效地将像素写入屏幕
【发布时间】:2012-11-28 16:08:39
【问题描述】:

我有一个像素数组 (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();

【问题讨论】:

  • 您是否尝试过将数据填充到位图中并将其渲染到屏幕上? GaussianBlur 由过滤器内核描述,您可以在渲染之前将其应用于数组的每个元素。

标签: graphics microsoft-metro directx direct2d


【解决方案1】:

尝试使用ID2D1RenderTarget::CreateBitmap()ID2D1RenderTarget::DrawBitmap()

【讨论】:

    【解决方案2】:

    如何为像素/图像添加高斯模糊效果?

    在 Direct2D 中有 effects (ID2D1Effect) 用于简单的位图处理。你可以自己写[看起来比较复杂],或者使用built-in effects之一[相当简单]。其中之一是Gaussian blur

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-02-19
      • 1970-01-01
      • 2012-04-20
      • 1970-01-01
      • 2018-02-18
      • 1970-01-01
      • 2014-09-26
      相关资源
      最近更新 更多