RT..
CBitmap bmTotal;
bmTotal.LoadBitmap(IDB_BITMAP_TOTAL);其中IDB_BITMAP_TOTAL图片为2张我需要图的组合.
定义CBitmap bm1,bm2;
如何把IDB_BITMAP_TOTAL图片对半拆分到上面两个CBitmap变量中?

解决方案 »

  1.   

    用GDI+ 后续的许多操作简便得多
    比如获得一个指定大小、位置等参数的位图对象可以用Clone()Bitmap::Clone Methods
    This topic lists the Clone methods of the Bitmap class. For a complete list of methods for the Bitmap class, see Bitmap Methods. Clone() 
    Clone(Rect& rect, PixelFormat format) 
    Clone(RectF& rect, PixelFormat format) 
    Clone(INT x, INT y, INT width, INT height, PixelFormat format) 
    Clone(REAL x, REAL y, REAL width, REAL, height, PixelFormat format) 
      

  2.   

    用bitblt画在一个hbitmap里是不是可以啊?
      

  3.   

    用StretchBlt画,不用定义定义CBitmap bm1,bm2;
      

  4.   

    BitBlt不能画到HBitmap里的吧
    StretchBlt的确可以实现..不过我还是需要能放到2个CBitmap里备用..
    还有其他的办法没?
      

  5.   

    bitblt进别的CBitmap中可满足需求?
      

  6.   

    BOOL BitBlt(
      HDC hdcDest, // handle to destination DC
      int nXDest,  // x-coord of destination upper-left corner
      int nYDest,  // y-coord of destination upper-left corner
      int nWidth,  // width of destination rectangle
      int nHeight, // height of destination rectangle
      HDC hdcSrc,  // handle to source DC
      int nXSrc,   // x-coordinate of source upper-left corner
      int nYSrc,   // y-coordinate of source upper-left corner
      DWORD dwRop  // raster operation code
    );
    BitBlt的目标不能为CBitmap类型吧..
      

  7.   

    直接读取源CBitmap中像素信息的数据,然后再CBitmap::CreateBitmap之。
      

  8.   

    hbitmap可以作为设备hdc吧!不作拉伸StretchBlt和bitblt不是一样吗?
      

  9.   

    自己写一个分割函数吧,也不是很难:BOOL Clone(CBitmap *SourceBitmap,CBitmap *SubBitmap,BYTE *SourceBit,BYTE *SubBit,int x,int y,int nWidth,int nHeight)
    {
    BITMAP bitmap;
    SourceBitmap->GetBitmap(&bitmap);
    int width=bitmap.bmWidth;
    //目前只能处理24位位图
    if(x>=bitmap.bmWidth || y>=bitmap.bmHeight || 32!=bitmap.bmBitsPixel)
    return FALSE;
    if(x+nWidth>=bitmap.bmWidth)
    nWidth=bitmap.bmWidth-x;
    if(y+nHeight>=bitmap.bmHeight)
    nHeight=bitmap.bmHeight-y;
    SourceBit=new BYTE[bitmap.bmWidth*bitmap.bmHeight*4];
    SubBit=new BYTE[nWidth*nHeight*4];
    SourceBitmap->GetBitmapBits(bitmap.bmWidth*bitmap.bmHeight*4,SourceBit);
    SubBitmap->DeleteObject(); //先清空原有的图片
    bitmap.bmWidth=nWidth;
    bitmap.bmHeight=nHeight;
    bitmap.bmWidthBytes=nWidth*4;
    SubBitmap->CreateBitmapIndirect(&bitmap);
    BYTE *temp=SubBit;
    for(int i=y;i<nHeight+y;i++)
    {
    for(int j=x;j<nWidth+x;j++)
    {
    *(temp++)=*(SourceBit+4*i*width+4*j);
    *(temp++)=*(SourceBit+4*i*width+4*j+1);
    *(temp++)=*(SourceBit+4*i*width+4*j+2);
    *(temp++)=*(SourceBit+4*i*width+4*j+3);
    }
    }
    SubBitmap->SetBitmapBits(nWidth*nHeight*4,SubBit);
    return TRUE;
    }
      

  10.   

    下面是这个函数的调用方法,函数各参数的含义就不说了,自己看一下就明白了:CStatic* pWnd = (CStatic*)GetDlgItem(IDC_STATIC1);
    pWnd->ModifyStyle(0, SS_BITMAP);
    CBitmap source,sub;
    source.LoadBitmap(IDB_BITMAP1);
    BYTE *SourceBit=0,*SubBit=0;
    if(Clone(&source,&sub,SourceBit,SubBit,10,10,250,250))
    pWnd->SetBitmap(sub);
    if(NULL!=SourceBit)
    {
    delete[]SourceBit;
    SourceBit=NULL;
    }
    if(NULL!=SubBit)
    {
    delete[]SubBit;
    SubBit=NULL;
    }
      

  11.   

    代码稍微再改进一下,就可以对单色位图、16色位图和256色位图进行处理,并且也可以很方便地进行X轴镜像、Y轴镜像或XY轴混合镜像,甚至拉伸(这个要自己插值)也是轻而易举的事。
      

  12.   

    Snow_Ice11111 
    我这出问题了.当把显示器调为16位色的时候Clone函数不启作用.求助!!!!
      

  13.   

    在Snow_Ice11111 的Clone函数中多次出现的4,
    感觉上好像是由bitmap.bmBitsPixel/8得来的,但是当16位的时候即为2,替换后程序运行会崩溃,无解了。