【发布时间】:2015-05-14 17:50:33
【问题描述】:
所以我最近通过并转换了我写的一个简单的测试应用程序来使用新版本的Direct2D,这意味着我基本上复制了the Direct2D Quickstart for Windows 8的相关部分。这很有效,因为我的应用程序表现得和以前一样(只是绘制了一堆像素。)
之前,为了更新位图,我做了以下操作:
for(int i = 0; i < 1000; ++i )
{
int x = rand()%600;
int y = rand()%600;
int index = 4 * ( x + ( y * 600 ) );
imageData[index] = rand()%256;
imageData[index+2] = 0;
}
D2D1_RECT_U rect2 = RectU(0,0,600,600);
pBitmap->CopyFromMemory(&rect2, imageData, 600*4);
imageData 只是:
imageData = new byte[600*600*4];
这仍然有效,但我认为既然我在闪亮的新 ID2D1Bitmap1 接口上拥有了这个漂亮的 Map 方法,我可以摆脱那个 CPU 端数组并执行以下操作:
D2D1_MAPPED_RECT* mapped = NULL;
ThrowIfFailed( pBitmap->Map( D2D1_MAP_OPTIONS_WRITE, mapped ) );
for(int i = 0; i < 1000; ++i)
{
int x = rand()%600;
int y = rand()%600;
int index = 4 * ( x + ( y * 600 ) );
mapped->bits[index] = rand()%256;
mapped->bits[index+2] = 0;
}
ThrowIfFailed(pBitmap->Unmap());
每次使用 E_INVALIDARG 调用 Map 时都会失败,使用传递给 CreateBitmap 的 D2D1_BITMAP_PROPERTIES1 中的 D2D1_BITMAP_OPTIONS 和调用 Map 中的 D2D1_MAP_OPTIONS 的各种组合。
查看D2D1_MAP_OPTIONS enumeration 的描述,似乎 3 个选项(READ、WRITE、DISCARD)实际上都不能用于我使用 Direct2D 上下文创建的位图......
如何在 Direct2D 中获得可以映射、写入、取消映射和绘制的位图?
【问题讨论】: