【发布时间】:2019-12-23 14:33:14
【问题描述】:
我需要为我在 Direct2D 中工作的光线投射器从像素数组创建位图。但是,我无法理解如何使用 CreateBitmap 函数。具体来说,我不确定srcData 参数应该是什么。我很确定/希望它是指向像素数组的指针,但我不确定如何设置该数组。它应该是什么样的数组?什么数据类型?等等。
这是我尝试过的:
int width = 400, height = 400;
D2D1::ColorF * arr = (D2D1::ColorF*)calloc(width * height * 4, sizeof(D2D1::ColorF));
for (int i = 0; i < width * height * 4; i++) { arr[i] = D2D1::ColorF(0.0f, 1.0f, 0.0f); }
// Create the bitmap and draw it on the screen
ID2D1Bitmap * bmp;
HRESULT hr;
hr = renderTarget->CreateBitmap(
D2D1::SizeU(width, height),
arr,
width * sizeof(int) * 4,
D2D1::BitmapProperties(),
&bmp);
if (hr != S_OK) { return; } // I've tested and found that hr does not equal S_OK
// Draw the bitmap...
第二行和第三行应该是什么样子?还有什么我做错了吗?
【问题讨论】: