首先,请阅读Link
要在c#中使用CreateDIBSection,我定义如下。
[DllImport("gdi32.dll", EntryPoint = "CreateDIBSection")]
public static extern IntPtr CreateDIBSection(IntPtr hdc, ref BITMAPINFO pbmi,
uint iUsage, out IntPtr ppvBits, IntPtr hSection, uint dwOffset);
我还定义了从Link学到的结构类型 像这样
public unsafe struct MY_BINFO
{
[MarshalAs(UnmanagedType.U4)]
public fixed uint bmiColors[3];
}
问题与我定义的MYBITMAPINFO有关。
[StructLayout(LayoutKind.Sequential)]
public unsafe struct MYBITMAPINFO
{
public BITMAPINFOHEADER bmiHeader;
[MarshalAs(UnmanagedType.U4)]
public fixed uint bmiColors[3];
}
当我调用CreateDIBSection函数时,MYBITMAPINFO被转换为BITMAPINFO类型,如此[LINK_1]
CreateDibSection(hdc, (const BITMAPINFO* )&dibInfo, ... ) //C++ code
但是,我不知道编写C#代码如何执行与上述代码相同的操作。(从MYBITMAPINFO到BITMAPINFO的类型转换)
感谢您的阅读。