加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

opencv的图象格式IplImage 和CBitmap的转换

发布时间:2020-12-14 02:58:20 所属栏目:大数据 来源:网络整理
导读:?? ???????? ? http://www.voidcn.com/article/p-uuoyvzxr-hn.html???? 分类: opencv 2012-05-08 16:46 774人阅读 评论(1) 收藏 举报 colors buffer dst byte null bi [cpp] view plain copy print ? ? BOOL ?IplImage2Bmp( HDC ?dc,IplImage?*pImage,CBitm
??
????????? http://www.voidcn.com/article/p-uuoyvzxr-hn.html????
分类: opencv 774人阅读 评论(1) 收藏 举报
colors buffer dst byte null bi
[cpp] view plain copy print ?
  1. ?BOOL?IplImage2Bmp(HDC?dc,IplImage?*pImage,CBitmap?*bitmap)??
  2. {??
  3. ?if(?pImage?&&?pImage->depth?==?IPL_DEPTH_8U?)??
  4. ????{??
  5. ????????uchar?buffer[sizeof(BITMAPINFOHEADER)?+?1024];??
  6. ????????BITMAPINFO*?bmi?=?(BITMAPINFO*)buffer;??
  7. ????????int?bmp_w?=?pImage->width,?bmp_h?=?pImage->height;??
  8. ???
  9. ????????//FillBitmapInfo(?bmi,?bmp_w,?bmp_h,?Bpp(),?pImage->origin?);??
  10. ??int?width=bmp_w;??
  11. ??int?height=bmp_h;??
  12. ??int?bpp=pImage???(pImage->depth?&?255)*pImage->nChannels?:?0;??
  13. ??int?origin=pImage->origin;??
  14. ??HBITMAP?hBitmap;??
  15. ??char*?dst_data?=?0;??
  16. ???
  17. ??assert(?bmi?&&?width?>=?0?&&?height?>=?0?&&?(bpp?==?8?||?bpp?==?24?||?bpp?==?32));??
  18. ???
  19. ??BITMAPINFOHEADER*?bmih?=?&(bmi->bmiHeader);??
  20. ???
  21. ??memset(?bmih,?0,?sizeof(*bmih));??
  22. ??bmih->biSize?=?sizeof(BITMAPINFOHEADER);??
  23. ??bmih->biWidth?=?width;??
  24. ??bmih->biHeight?=?origin???abs(height)?:?-abs(height);??
  25. ??bmih->biPlanes?=?1;??
  26. ??bmih->biBitCount?=?(unsigned?short)bpp;??
  27. ??bmih->biCompression?=?BI_RGB;??
  28. ???
  29. ??if(?bpp?==?8?)??
  30. ??{??
  31. ???RGBQUAD*?palette?=?bmi->bmiColors;??
  32. ???int?i;??
  33. ???for(?i?=?0;?i?<?256;?i++?)??
  34. ???{??
  35. ????palette[i].rgbBlue?=?palette[i].rgbGreen?=?palette[i].rgbRed?=?(BYTE)i;??
  36. ????palette[i].rgbReserved?=?0;??
  37. ???}??
  38. ??}??
  39. ??if(bitmap->m_hObject!=NULL)??
  40. ??{??
  41. ???bitmap->Detach();??
  42. ??}??
  43. ??hBitmap=CreateDIBitmap(dc,bmih,CBM_INIT,pImage->imageData,bmi,DIB_RGB_COLORS);??
  44. ??bitmap->Attach(hBitmap);??
  45. ??return?TRUE;??
  46. ????}??
  47. ?return?FALSE;??
  48. ???
  49. }??

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读