求高手指点 用mfc cimage类如何实现图像的裁剪功能 

解决方案 »

  1.   

    void CvrhumanView::OnLButtonDown(UINT nFlags, CPoint point)
    {
    // TODO: 在此添加消息处理程序代码和/或调用默认值
    originpoint.x=point.x;
    originpoint.y=point.y;

    CFormView::OnLButtonDown(nFlags, point);
    }void CvrhumanView::OnLButtonUp(UINT nFlags, CPoint point)
    {
    // TODO: 在此添加消息处理程序代码和/或调用默认值

    endpoint.x=point.x;
    endpoint.y=point.y;
    cutwidth=endpoint.x-originpoint.x;
    cutheight=endpoint.y-originpoint.y; LONG imageWidth = _cimage->GetWidth();
    LONG imageHeight = _cimage->GetHeight(); 

    BYTE* bits = (BYTE*)_cimage->GetBits(); BYTE* dstImage=new BYTE[cutheight*cutwidth];
        memset(dstImage,(BYTE)255,cutheight*cutwidth);
    for ( int i =  0 ; i < cutheight; ++ i )
    {
    for ( int j  = 0 ; j  < cutwidth ; ++ j )
    {
    dstImage [i  * cutwidth + j] = bits[ (i+originpoint.y) * _cimage->GetPitch() +(j+originpoint.x )];
    }
    } //for ( int i =  0 ; i < cutheight; ++ i )//测试用
    //{
    // for ( int j  = 0 ; j  < cutwidth ; ++ j )
    // {
    //  bits[ i*_cimage->GetPitch() +j]= dstImage [i  * cutwidth  + j];
    // }
    //} //Invalidate();//测试用 _cimage->Destroy(); _cimage->Create(cutwidth,cutheight,8,0); BYTE* bits1 = (BYTE*)_cimage->GetBits();
    for ( int i =  0 ; i < cutheight; ++ i )
    {
    for ( int j  = 0 ; j  < cutwidth ; ++ j )
    {
    bits1[ i * _cimage->GetPitch() +j] = dstImage [i* cutwidth + j];
    }
    }

    Invalidate();
    delete dstImage;
    dstImage = NULL;
    CFormView::OnLButtonUp(nFlags, point);
    }void CvrhumanView::OnDraw(CDC* pDC)
    { if ( _cimage != NULL ) 
    {
    CRect rctWindowSize;
    GetClientRect(rctWindowSize);
    //_cimage->StretchBlt(dc,0,0,rctWindowSize.Width(),rctWindowSize.Height(),SRCCOPY);
    _cimage->StretchBlt(pDC->m_hDC,0,0,_cimage->GetWidth(),_cimage->GetHeight(),SRCCOPY); }

    }这是我自己写的代码 但是显示时截取的图像光显示黑色  源图像中截取的信息没法保存下来  请多多帮忙!
      

  2.   

    cximage有个crop函数,你可以试验一下。
      

  3.   

    http://www.codeproject.com/KB/graphics/cximage.aspx
    自己下载cximage看,里面代码都现成的!
      

  4.   

    就是,这个问题CxImage确实是非常好的例子