简体   繁体   English

HBITMAP *位图到.net位图

[英]HBITMAP *Bitmap to .net Bitmap

I have a Dll and the header file for it, and I'm trying to create a COM wrapper in C++ to use in C#. 我有一个Dll和它的头文件,并且试图在C ++中创建一个COM包装器以在C#中使用。
For most of functions it was very simple since they were returning int or string . 对于大多数函数来说,这很简单,因为它们返回的是intstring

I have this struct in the header file. 我在头文件中有此结构。

virtual HRESULT STDMETHODCALLTYPE GetBMP( 
            int Width,
            int Height,
            HBITMAP *Bitmap) = 0;

My problem is that since I'm way out of my league with C++ I don't know how to convert the HBITMAP to something more appropriated to .net style 我的问题是,由于我与C ++脱节,所以我不知道如何将HBITMAP转换为更适合.net风格的内容。

Thanks in advance, and please forgive me if wrote stupid things 在此先感谢您,如果写了愚蠢的东西请原谅

UPDATE: I tried something like this : 更新:我尝试过这样的事情:

HBITMAP GetBMP(int Width, int Height)
{

    HBITMAP bm = 0; 
    m_piHelper->GetBMP(Width,Height,&bm);   
    return bm ;

}

The problem obviously is after that in c# how convert from 'HBITMAP__*' to 'System.IntPtr to use it with bitmap.fromHbitmap 问题显然是在c#之后,如何从'HBITMAP __ *'转换为'System.IntPtr以与bitmap.fromHbitmap一起使用

The parameter should be out IntPtr . 该参数应为out IntPtr

Then you can create an additional function that will call GetBMP and then call Bitmap.FromHbitmap to return a bitmap. 然后,您可以创建一个附加函数,该函数将调用GetBMP ,然后调用Bitmap.FromHbitmap以返回位图。 Such function must then DeleteObject the original hbitmap . 然后,该函数必须将DeleteObject hbitmap为原始hbitmap

您也许应该尝试System.IntPtr。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM