CBitmap Bmp;//载入位图
Bmp.LoadBitmap(IDB_BITMAP_BK_IMG);
HBITMAP hBmp = HBITMAP(Bmp);//将CBitmap转换为HBITMAP
BITMAP bmp;
Bmp.GetBitmap(&bmp);//获得位图信息
int depth,nChannels;
if(bmp.bmBitsPixel==1)//得到图像深度和通道数
{depth=IPL_DEPTH_1U; nChannels=1;
} else {
depth=IPL_DEPTH_8U;
nChannels=bmp.bmBitsPixel/8;
}
IplImage* m_load_image = cvCreateImage(cvSize(bmp.bmWidth,bmp.bmHeight), depth, nChannels); //创建图像
BYTE *pBuffer = new BYTE[bmp.bmHeight*bmp.bmWidth*nChannels]; //创建缓冲区
GetBitmapBits(hBmp, bmp.bmHeight*bmp.bmWidth*nChannels, pBuffer); //将位图信息复制到缓冲区
memcpy(m_load_image->imageData, pBuffer, bmp.bmHeight*bmp.bmWidth*nChannels);//将缓冲区信息复制给IplImage
int destimgSize;
destimgSize = m_load_image->height*m_load_image->width*3;
int srcImgTotalSize;
srcImgTotalSize = m_load_image->widthStep*m_load_image->height;
char * buffer = new char[destimgSize];//用于存储处理后的图片数据
IplImage* m_bk_image = cvCreateImage(cvGetSize(m_load_image),IPL_DEPTH_8U,3);
int destCout=0;
char * pSrcData = m_load_image->imageData;
for (int i=1;i<=srcImgTotalSize;i++)
{
if (i%4 == 0)
{
continue;
}
buffer[destCout] = *(pSrcData + i-1);
destCout++;
}
m_bk_image->imageData = buffer;