在c#中,PInvoke一个函数,需要传递如下结构参数:
typedef struct tagIMAGE
{
DWORD dwWidth;
DWORD dwHeight;
unsigned char* pBits;
unsigned char* pPalette;
WORD wBitsPerPixel;
}IMAGE, *pIMAGE ;
请问怎么能把bitmap类型,转化成改结构类型?谢谢
typedef struct tagIMAGE
{
DWORD dwWidth;
DWORD dwHeight;
unsigned char* pBits;
unsigned char* pPalette;
WORD wBitsPerPixel;
}IMAGE, *pIMAGE ;
请问怎么能把bitmap类型,转化成改结构类型?谢谢
不过可以一个一个来,图象的高度和宽度容易知道,pPalette和pBits
需要用CreateFile和ReadFile来打开文件,具体怎么对应忘了,可以到baidu上搜下
Bitmap、BitmapData 都去看看 以及他们的关系。
DWORD biSize;
LONG biWidth;
LONG biHeight;
WORD biPlanes;
WORD biBitCount;
DWORD biCompression;
DWORD biSizeImage;
LONG biXPelsPerMeter;
LONG biYPelsPerMeter;
DWORD biClrUsed;
DWORD biClrImportant;
} BITMAPINFOHEADER, *PBITMAPINFOHEADER;
这个是图象的头文件,可以获得一些信息
typedef struct tagBITMAPFILEHEADER {
WORD bfType;
DWORD bfSize;
WORD bfReserved1;
WORD bfReserved2;
DWORD bfOffBits;
} BITMAPFILEHEADER, *PBITMAPFILEHEADER;
这个是图象文件的信息,可以获得关于这个文件的信息
如果需要找到pBits 用这个可以读取到ReadFile(hFile, lpbi, dwImageBytes, &dwRead, NULL);
{
DWORD dwWidth;
DWORD dwHeight;
unsigned char* pBits;
unsigned char* pPalette;
WORD wBitsPerPixel;
}IMAGE, *pIMAGE 但是如果使用 FieldOffset 恐怕要提前知道的 pBits 和 pPalette 内存的长度