//这是把一张150*150的BMP图片拼成10行10列,成为一个1500*1500的图
void CTestDlg::OnPaint() 
{
CClientDC dc(this);
m_dcMem.CreateCompatibleDC( &dc );
HBITMAP hBmpNew = (HBITMAP)LoadImage(AfxGetInstanceHandle(), "E:\\tablen.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); 
if( hBmpNew != NULL )
{
HBITMAP hBmpOld = (HBITMAP)SelectObject(m_dcMem, hBmpNew);
BITMAP bmInfo; 
GetObject( hBmpNew , sizeof(BITMAP), &bmInfo ); int iX = 0;
int iY = 0;
for (int iRowIndex = 0; iRowIndex < 10; iRowIndex++)
{
for (int iColIndex = 0; iColIndex < 10; iColIndex++)
{
dc.BitBlt(iX, iY, bmInfo.bmWidth, bmInfo.bmHeight, &m_dcMem, 0, 0, SRCCOPY); iX += bmInfo.bmWidth;
} iX = 0;
iY += bmInfo.bmHeight;
} DeleteObject(hBmpNew);
}
CDialog::OnPaint();
}我想问的是,如何让这拼接步骤在内存DC中做,然后把拼好的图一次性的画在屏幕DC上?
也就是:void CTestDlg::DrawMem()
{
//把一张150*150的BMP图片拼成10行10列,成为一个1500*1500的图
         //这里怎么写呢?
}
void CTestDlg::OnPaint() 
{
CClientDC dc(this);
dc.BitBlt(iX, iY, bmInfo.bmWidth, bmInfo.bmHeight, &m_dcMem, 0, 0, SRCCOPY); CDialog::OnPaint();
}

解决方案 »

  1.   

    void CTestDlg::DrawMem(CDC *pDC)
    {
        //把一张150*150的BMP图片拼成10行10列,成为一个1500*1500的图
             //这里怎么写呢?
    }
    void CTestDlg::OnPaint() 
    {
        CClientDC dc(this);    CMemDC memDC(&dc);
        DrawElement(memDC);    memDC.BitBlt(iX, iY, bmInfo.bmWidth, bmInfo.bmHeight, &m_dcMem, 0, 0, SRCCOPY);    CDialog::OnPaint();
    }
      

  2.   

    SIZE CTestDlg::DrawMem(CDC *memDC)
    {
    SIZE bmSize;
    CDC hDC;
    hDC.CreateCompatibleDC( memDC);
        HBITMAP hBmpNew = (HBITMAP)LoadImage(AfxGetInstanceHandle(), "E:\\tablen.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); 
        if( hBmpNew != NULL )
        {
            HBITMAP hBmpOld = (HBITMAP)SelectObject(hDC, hBmpNew);
            BITMAP bmInfo; 
            GetObject( hBmpNew , sizeof(BITMAP), &bmInfo );
            bmSize.cx = bmInfo.bmWidth;
            bmSize.cy = bmInfo.bmHeight;
            int iX = 0;
            int iY = 0;
            for (int iRowIndex = 0; iRowIndex < 10; iRowIndex++)
            {
                for (int iColIndex = 0; iColIndex < 10; iColIndex++)
                {
                    memDC->BitBlt(iX, iY, bmInfo.bmWidth, bmInfo.bmHeight, &hDC, 0, 0, SRCCOPY);                iX += bmInfo.bmWidth;
                }            iX = 0;
                iY += bmInfo.bmHeight;
            }        DeleteObject(hBmpNew);
        }
        return bmSize;
    }void CTestDlg::OnPaint() 
    {
        CClientDC dc(this);
        m_dcMem.CreateCompatibleDC( &dc );
        SIZE bmSize = DrawMem(&m_dcMem);
        dc.BitBlt(0,0,bmSize.cx*10, bmSize.cy*10, &m_dcMem, 0, 0, SRCCOPY);    CDialog::OnPaint();
    }
      

  3.   

    只要楼主再多创建一个DC就可以了.
    //这是把一张150*150的BMP图片拼成10行10列,成为一个1500*1500的图
    void CTestDlg::OnPaint() 
    {
        CClientDC dc(this);
        m_dcMem.CreateCompatibleDC( &dc );
       CDC hDC;
       hDC.CreateCompatibleDC( m_dcMem);    HBITMAP hBmpNew = (HBITMAP)LoadImage(AfxGetInstanceHandle(), "E:\\tablen.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); 
        if( hBmpNew != NULL )
        {
            HBITMAP hBmpOld = (HBITMAP)SelectObject(hDC, hBmpNew);
            BITMAP bmInfo; 
            GetObject( hBmpNew , sizeof(BITMAP), &bmInfo );        int iX = 0;
            int iY = 0;
            for (int iRowIndex = 0; iRowIndex < 10; iRowIndex++)
            {
                for (int iColIndex = 0; iColIndex < 10; iColIndex++)
                {
                    m_dcMem.BitBlt(iX, iY, bmInfo.bmWidth, bmInfo.bmHeight, &hDC, 0, 0, SRCCOPY);                iX += bmInfo.bmWidth;
                }            iX = 0;
                iY += bmInfo.bmHeight;
            }        DeleteObject(hBmpNew);
        }    dc.BitBlt(iX, iY, bmInfo.bmWidth, bmInfo.bmHeight, &m_dcMem, 0, 0, SRCCOPY);    CDialog::OnPaint();
    }