gpt4 book ai didi

c++ - ID2D1Bitmap1::Map,什么时候可以用?

转载 作者:行者123 更新时间:2023-11-28 07:46:36 25 4
gpt4 key购买 nike

所以我最近完成并转换了我编写的一个简单的测试应用程序以使用新版本的 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];

这仍然有效,但我认为既然我在 Shiny 的新 ID2D1Bitmap1 接口(interface)上有了这个漂亮的 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());

这每次都使用 D2D1_BITMAP_OPTIONS 的各种组合在使用 E_INVALIDARG 调用 Map 时失败在 D2D1_BITMAP_PROPERTIES1 传递给 CreateBitmap 和 D2D1_MAP_OPTIONS在对 Map 的调用中。

查看 D2D1_MAP_OPTIONS enumeration 的描述似乎这 3 个选项(READ、WRITE、DISCARD)实际上都不能用于我使用 Direct2D 上下文创建的位图...

在 Direct2D 中,我如何获得可以映射、写入、取消映射和绘制的位图?

最佳答案

您的问题是您的映射指针不应该是空指针。我建议根据以下内容更改您的代码:

D2D1_MAPPED_RECT 已映射;

ThrowIfFailed( pBitmap->Map( D2D1_MAP_OPTIONS_WRITE, &mapped ) );

关于c++ - ID2D1Bitmap1::Map,什么时候可以用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14791546/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com