这是单文档的工程,在View类添加的函数,大神们,我错在哪儿了啊,求指教,为神马我的工程里面调用执行了之后,一片空白RGB没有问题,都是正常的
void CDetectDefectView::PrePainting()
{
CClientDC dc(this); CBrush ***pBrush=new CBrush **[height];
CBrush *pOldBrush; PNT Axy,Bxy;
int i,j;
for (i=0;i<height;i++)
{
pBrush[i]=new CBrush *[width];
for (j=0;j<width;j++)
{
Axy.x=unit_length*i*1.0e-2;//delta_x基本上在0.2左右
Axy.y=unit_length*j*1.0e-2;//delta_y基本上在0.2左右
Bxy.x=unit_length*(i+1)*1.0e-2;
Bxy.y=unit_length*(j+1)*1.0e-2; pBrush[i][j]=new CBrush(RGB(RGB_data[i][j],0,255-RGB_data[i][j]));
//?寶嬻夋嶞丆杊巭幷?撪梕
pOldBrush=dc.SelectObject(pBrush[i][j]);//??夋嶞 dc.Rectangle(Axy.x,Axy.y,Bxy.x,Bxy.y);
dc.SelectObject(pOldBrush);
DeleteObject(pOldBrush); }
}}
VS2008CBrushOnDraw

解决方案 »

  1.   

    Brush什么时候用,什么时候申请。你new个这么复杂的指针干什么啊。保存在那里有用吗?
    简单调试一下,在dc.Rectangle(Axy.x,Axy.y,Bxy.x,Bxy.y);加断点,看看四个坐标点的值,是否在屏幕可见区。
      

  2.   


    版主好,我跟了程序,Axy的最小从0开始一直到300多,应该是在屏幕内了吧,然后及时补new这么复杂的指针,效果也是一样,神马都看不见,height=1024,width=768,求版主多指教了
      

  3.   

    版主好,
    void CDetectDefectView::Proceed()
    {
    ReadinCsv();
    ChangeToRGB();
    PrePainting();
    }
    void CDetectDefectView::OnFileOpen()
    {


    。 Proceed();}
    这是一个从CSV文件读取数据然后画图的过程,所以直接在OnFileOpen调用了
      

  4.   

    还要在ondraw或者onpaint时时画出来才行
      

  5.   


    神马意思呀版主,难道在自己的函数里面调用OnDraw或者OnPaint吗
      

  6.   

    dc.FillRect
      

  7.   

    LZ忙活了半天,构造了Brush,但是没有使用它嘛,你的pdc->FillRect()呢?
      

  8.   

    各位大神,我改成下面的形式,可是为什么每次到i=4,j=866的时候就挂了呢
    void CDetectDefectView::Painting(POINT Axy,POINT Bxy,double rgb,int iii, int jjj)
    {
    CDetectDefectDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    if (!pDoc)
    return; CDC *pDC=GetDC();
    // CBrush::CBrush.
    CBrush brush1;   // Must initialize!
    brush1.CreateSolidBrush(RGB(255-rgb,0,rgb));   // Blue brush. CBrush* pTempBrush = NULL;
    //CBrush OrigBrush;
    pTempBrush = (CBrush*)pDC->SelectObject(&brush1);
    // Save original brush.
    //OrigBrush.FromHandle((HBRUSH)pTempBrush);
    // Paint upper left corner with blue brush.
    pDC->Rectangle(Axy.x, Axy.y, Bxy.x, Bxy.y);
    pDC->SelectObject(&pTempBrush);
    DeleteObject(pTempBrush);
    //delete();
    //UpdateData(TRUE);}
    void CDetectDefectView::PrePainting()
    {
    CDetectDefectDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    if (!pDoc)
    return; ofstream fout;
    fout.open("output.txt");
    fout<<"数据输出"<<"\n";
    fout<<"数据形式:RGB_data"<<"\n"; POINT Axy,Bxy;
    int i,j;
    for (i=0;i<height;i++)
    {
    for (j=0;j<width;j++)
    {
    Axy.x=i;
    Axy.y=j;
    Bxy.x=(i+1);
    Bxy.y=(j+1);
    fout<<RGB_data[i][j]<<"   "; Painting(Axy,Bxy,RGB_data[i][j],i,j);

    }
    fout<<"\n";
    }
    fout.close();}
      

  9.   

    dc.Rectangle(Axy.x,Axy.y,Bxy.x,Bxy.y); 使用 pen 不是 brushvoid CChildDlg::OnPaint() 
    {
    CDialog::OnPaint();// for painting messages
    int height=200;
    int width =200;
    int unit_length=100;
    CClientDC dc(this); CBrush ***pBrush=new CBrush **[height];
    CBrush *pOldBrush; POINT Axy,Bxy;
    int i,j;
    for (i=0;i<height;i++)
    {
    pBrush[i]=new CBrush *[width];
    for (j=0;j<width;j++)
    {
    Axy.x=(LONG)(unit_length*i*1.0e-2);//delta_x基本上在0.2左右
    Axy.y=(LONG)(unit_length*j*1.0e-2);//delta_y基本上在0.2左右
    Bxy.x=(LONG)(unit_length*(i+1)*1.0e-2);
    Bxy.y=(LONG)(unit_length*(j+1)*1.0e-2); pBrush[i][j]=new CBrush(RGB(i*j,0,255)); pOldBrush=dc.SelectObject(pBrush[i][j]);
    CRect rc;
    rc.SetRect(Axy.x,Axy.y,Bxy.x,Bxy.y);
    dc.FillRect(&rc,pBrush[i][j]);
    dc.SelectObject(pOldBrush);
    DeleteObject(pOldBrush);
    }
    }
    }
    注意内存泄露 !!!
      

  10.   

    VC中在MFC程序用循环做这些都是扯蛋啊,今天在公司遇到同样的问题,后来做了一点改变,人搞的腿酸手都发抖,但是软件利索多了,而且发现居然有惊人的效果.