码迷,mamicode.com
首页 > 其他好文 > 详细

iplimage 转HBITMAP

时间:2016-01-19 15:43:21      阅读:326      评论:0      收藏:0      [点我收藏+]

标签:

HBITMAP  IplImage2hBitmap(IplImage* pImg)
{
    cvFlip(pImg, NULL);
    BYTE tmp[sizeof(BITMAPINFO)+1024];
    BITMAPINFO *bmi = (BITMAPINFO*)tmp;
    HBITMAP hBmp;
    int i;
    memset(bmi,0,sizeof(BITMAPINFO));
    bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    bmi->bmiHeader.biWidth = pImg->width;
    bmi->bmiHeader.biHeight = pImg->height; 
    bmi->bmiHeader.biPlanes = 1;
    bmi->bmiHeader.biBitCount = pImg->nChannels * pImg->depth;
    bmi->bmiHeader.biCompression = BI_RGB;
    bmi->bmiHeader.biSizeImage = 0;//if biCompression is BI_RGB,this can be 0
    bmi->bmiHeader.biClrImportant =0 ;

    switch(pImg->nChannels * pImg->depth) 
    { 
    case 8 : 
        for(i=0 ; i < 256 ; i++){ 
            bmi->bmiColors[i].rgbBlue = i;
            bmi->bmiColors[i].rgbGreen= i;
            bmi->bmiColors[i].rgbRed= i;
        }
        break;
    case 32:
    case 24: 
        ((DWORD*) bmi->bmiColors)[0] = 0x00FF0000;
        ((DWORD*) bmi->bmiColors)[1] = 0x0000FF00;
        ((DWORD*) bmi->bmiColors)[2] = 0x000000FF;
        break; 
    } 
    hBmp = ::CreateDIBSection(NULL,bmi,DIB_RGB_COLORS,NULL,0,0);

    SetDIBits(NULL,hBmp,0,pImg->height,pImg->imageData,bmi,DIB_RGB_COLORS);

    return hBmp;
}

 

iplimage 转HBITMAP

标签:

原文地址:http://www.cnblogs.com/qq76211822/p/5142338.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!