C# Marshal / Pinvoke CBitmap?
我不知道如何将 C++ CBitmap 封送到 C# 位图或图像类。
我的导入如下所示:
[DllImport(@"test.dll", CharSet = CharSet.Unicode)] 公共静态 extern IntPtr GetBitmap(System.IntPtr hwnd, int nBMPWIDTH, int nBMPHEIGHT);
H 文件部分如下所示:
Cbitmap* GetBitmap(HWND hwnd,int nBMPWIDTH,int nBMPHEIGHT);
如何将 Cbitmap 转换为可以在 C# 中显示的内容?
非常感谢。
I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class.
My import looks like this:
[DllImport(@"test.dll", CharSet = CharSet.Unicode)]
public static extern IntPtr GetBitmap(System.IntPtr hwnd, int nBMPWIDTH, int nBMPHEIGHT);
The H file section looks like:
Cbitmap* GetBitmap(HWND hwnd,int nBMPWIDTH,int nBMPHEIGHT);
How do I go about converting the Cbitmap into something I can display in C#?
Many thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
.NET Framework 中最接近的 API 是 Image.FromHbitmap,但这需要您从 CBitmap 中提取 HBITMAP,而在 C# 中则无法做到这一点(至少在不了解 CBitmap 内部结构的情况下无法做到)。如果您可以修改 C++ GetBitmap 函数以返回 HBITMAP 而不是 CBitmap 包装器,那么这将是最简单的解决方案。这是你的选择吗?
The closest API in the .NET Framework is Image.FromHbitmap, but this would require you to extract the HBITMAP from the CBitmap, which you can't do in C# (at least not without knowing the internals of CBitmap). If it's possible for you to modify your C++ GetBitmap function to return the HBITMAP rather than the CBitmap wrapper, that would be the easiest solution. Is that an option for you?