当编译器遇到函数 memcpy() 时,程序停止工作并显示消息框“name_program has stopworking
”。
这是函数:
IplImage* hBitmap2Ipl(HBITMAP hBmp)
{
BITMAP bmp;
::GetObject(hBmp,sizeof(BITMAP),&bmp);
int nChannels = bmp.bmBitsPixel == 1 ? 1 : bmp.bmBitsPixel/8 ;
// get depth color bitmap or grayscale
int depth = bmp.bmBitsPixel == 1 ? IPL_DEPTH_1U : IPL_DEPTH_8U;
IplImage* img = cvCreateImageHeader( cvSize(bmp.bmWidth, bmp.bmHeight), depth,
nChannels );
// Copy bitmap data to IplImage
img->imageData = (char*)malloc(bmp.bmHeight*bmp.bmWidth*nChannels*sizeof(char));
memcpy(img->imageData,(char*)(bmp.bmBits),bmp.bmHeight*bmp.bmWidth*nChannels);
return img;
}
但这非常有效:
int a[10];
int b[10];
memcpy(a, b, 10);
最佳答案
GetObject
不会返回 bmBits
成员的有效指针 - 它仅填充结构的其他成员。
您需要使用类似 GetDIBits
的内容相反。
关于c - 函数 memcpy() 正在关闭程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26984609/