(1 )IplImage -> Bitmap and Bitmap -> IplImage
IplImage *img ; Bitmap bitmap( 20 ,20 ,PixelFormat24bppRGB ) ; Graphics pGra( & bitmap) ; HDC hdc = pGra ->GetHDC() ; CvImage cvimg ; cvimg.CopyOf( img , -1) ; RECT rect = { 0 , 0 , img ->width , img ->height } ; cvimg.DrawToHDC( hdc , &rect ) ; pGra ->ReleaseHDC( hdc ) ; IplImage *tempimg = cvCreateImage(cvSize(bitmpa ->GetWidth() , bitmap->Getheight(), 8 , 3) ; BitmapData mydata; Rect rect(0, 0, bitmpa ->GetWidth() , bitmap ->Getheight()) ; bitmap.LockBits( &rect , ImageLockModeRead , PixelFormat24bppRGB ,&mydata) ; memcpy(tempimg ->imagedata, mydata.scan0 , tempimg->width * tempimg->height* 3) ; bitmap.UnlockBits( & objdata ) ;
(2) CBitmap ->Bitmap adn Bitmap -> CBitamp
CDC *pdc = this ->GetDC() ; CBitmap m_Cbit; m_Cbit.CreateCompatibleBitmap(pdc , 100 ,100 ) ; Bitmap m_bit((HBITMAP) m_Cbit , NULL) ; HBITMAP bitmap ; m_bit.GetHBITMAP( Color( 0 , 0 , 0) , & bitmap ) ; CBitmap *m_pbit = CBitmap ::FromHandle( bitmap) ; ...do something ; m_pbit->DeleteObject() ;
(3) IplImage ->CBitmap , Cbitmap ->IplImage
CDC *pdc = this ->GetDC() ; IplImage *img = cvCreateImage( cvSize( 100,100 ) , 8 , 3 ); CBitmap m_bitmap ; m_bitmap.CreateCompatibleBitmap( pdc , 100 ,100 ) ; CDC memdc ; memdc.CreateCompatibleDC( pdc ) ; CBitmap *pold = memdc .SelectObject( &m_bitmap) ; CvvImage cvimg ; Rect rect(0 , 0 , 100,100 ) ; cvimg.CopyOf( img , -1 ) ; cvimg.DrawToHDC( memdc.m_hDC , &rect ) ; ReleaseDC( pdc) ; IplImage *tempimg = cvCloneImage( img ) ; m_bitmap.GetBitmapBits( img ->widthStep * img ->height , img ->imageData) ;
CDC *pdc = this ->GetDC() ; IplImage *img = cvCreateImage( cvSize( 100,100 ) , 8 , 3 ); CBitmap m_bitmap ; m_bitmap.CreateCompatibleBitmap( pdc , 100 ,100 ) ; CDC memdc ; memdc.CreateCompatibleDC( pdc ) ; CBitmap *pold = memdc .SelectObject( &m_bitmap) ; CvvImage cvimg ; Rect rect(0 , 0 , 100,100 ) ; cvimg.CopyOf( img , -1 ) ; cvimg.DrawToHDC( memdc.m_hDC , &rect ) ; ReleaseDC( pdc) ; IplImage *tempimg = cvCloneImage( img ) ; m_bitmap.GetBitmapBits( img ->widthStep * img ->height , img ->imageData) ;