这是单文档的工程,在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
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
简单调试一下,在dc.Rectangle(Axy.x,Axy.y,Bxy.x,Bxy.y);加断点,看看四个坐标点的值,是否在屏幕可见区。
版主好,我跟了程序,Axy的最小从0开始一直到300多,应该是在屏幕内了吧,然后及时补new这么复杂的指针,效果也是一样,神马都看不见,height=1024,width=768,求版主多指教了
void CDetectDefectView::Proceed()
{
ReadinCsv();
ChangeToRGB();
PrePainting();
}
void CDetectDefectView::OnFileOpen()
{
。
。
。 Proceed();}
这是一个从CSV文件读取数据然后画图的过程,所以直接在OnFileOpen调用了
神马意思呀版主,难道在自己的函数里面调用OnDraw或者OnPaint吗
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();}
{
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);
}
}
}
注意内存泄露 !!!