如何使用Direct2D有效地将像素写入屏幕 [英] How to efficiently write pixels to the screen with Direct2D

查看:386
本文介绍了如何使用Direct2D有效地将像素写入屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像素数组(m_​​pixels),我想使用Direct2D渲染到屏幕上。
该数组包含10,000个元素(100行,每行100个像素)。以下代码循环遍历像素,并将它们绘制为10x10矩形的屏幕。有执行此操作的更有效方法吗?如何为像素/图像添加高斯模糊效果?

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();


推荐答案

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

这篇关于如何使用Direct2D有效地将像素写入屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆