BitmapSource::Create 编译错误 C2665 - 数组参数无效?

发布于 2024-10-10 04:56:40 字数 1210 浏览 0 评论 0原文

这里的第一篇文章:

-深呼吸

-为了“windowise”一个在 OpenGL 中全屏运行得很好的应用程序(它本质上是从网络摄像头获取数据,在显示它之前稍微处理一下),我决定采取一些纹理数据并尝试将其绘制在 Windows 窗体上。

我决定用托管数组替换 malloc 的非托管内存块,然后使用它创建一个 BitmapSource,用它来制作一个图像,然后我可以使用 DrawImage() 到表单。

实际上,这就是我所处的位置:

cli::array<char>^ MyArray = gcnew cli::array<char>(10000);

BitmapSource^ bmpSource = BitmapSource::Create(
(int)g_nTexMapX,
(int)g_nTexMapY,
(int)300,
(int)300,
(System::Windows::Media::PixelFormat)PixelFormats::Rgb24,
(int)0,
MyArray,
(unsigned int)(g_nTexMapX*3 +(g_nTexMapX*3) %4));

我遇到了错误 C2665 - 显然是在抱怨我的参数与预期的重载不匹配,而 MyArray 是罪魁祸首。

很可能是见树不见林的情况,但如果伴随着纠正,我很乐意接受不可避免的指点和笑声,这将使我能够按计划继续我的生活。

非常感谢。

以下答案:

我决定只是找到从非托管数据实例化的重载,我会这样做,但解决方案无论哪种方式都有效:

IntPtr myPixels = (IntPtr)g_pTexMap; // <- Pointer to my pixel data.

BitmapSource^ bmpSource = BitmapSource::Create(
    (int)g_nTexMapX,
    (int)g_nTexMapY,
    300.0,
    300.0,
    PixelFormats::Rgb24,
    nullptr,
    myPixels,
    (int)(g_nTexMapX * g_nTexMapY * 3),
    (int)(g_nTexMapX*3 +(g_nTexMapX*3) %4));

另外,我必须感谢您为我提供“nullptr” ' 在尝试了 0、null、NULL 等之后,我开始发疯了!

First post here:

-Deep Breath-

In order to 'windowise' an app that works pretty well fullscreen in OpenGL (which essentially takes data from a webcam, mucks about a bit before displaying it) I've decided to take a bit lump of texture data and attempt to get this to draw on a Windows Form.

I'm determined to substitute the malloc'd lump of unmanaged memory with a managed array and then use this to create a BitmapSource with which to make an Image which I can then DrawImage() to the Form.

Effectively, here's where I am:

cli::array<char>^ MyArray = gcnew cli::array<char>(10000);

BitmapSource^ bmpSource = BitmapSource::Create(
(int)g_nTexMapX,
(int)g_nTexMapY,
(int)300,
(int)300,
(System::Windows::Media::PixelFormat)PixelFormats::Rgb24,
(int)0,
MyArray,
(unsigned int)(g_nTexMapX*3 +(g_nTexMapX*3) %4));

and I'm greeted with error C2665 - apparently complaining that my parameters don't match either of the overloads expected and that MyArray is the culprit.

Most likely a case of not seeing the wood for the trees here but I'd be happy to take the inevitable pointing and laughing if accompanied by a correction which will allow me to continue with my life as planned.

Many thanks in advance.

Following answer:

I decided having just found the overload which instantiates from unmanaged data that I'd go with that but the solution works either way:

IntPtr myPixels = (IntPtr)g_pTexMap; // <- Pointer to my pixel data.

BitmapSource^ bmpSource = BitmapSource::Create(
    (int)g_nTexMapX,
    (int)g_nTexMapY,
    300.0,
    300.0,
    PixelFormats::Rgb24,
    nullptr,
    myPixels,
    (int)(g_nTexMapX * g_nTexMapY * 3),
    (int)(g_nTexMapX*3 +(g_nTexMapX*3) %4));

Also I've got to say thank you for offering me 'nullptr' which after trying 0, null, NULL etc was starting to drive me nuts!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

微凉徒眸意 2024-10-17 04:56:40

你正在给自己带来麻烦。第三个和第四个参数是 double,而不是 int。第 6 个参数是一个对象,而不是 int,传递 nullptr。该数组不是托管类型的数组,请使用 Byte。最后一个参数是 int,而不是 unsigned int。

我不得不建议你回顾一下你的编程风格。

You are casting yourself into trouble. The 3rd and 4th arguments are double, not int. The 6th argument is an object, not an int, pass nullptr. The array is not an array of a managed type, use Byte. The last argument is an int, not an unsigned int.

I'd have to recommend you review your programming style.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文