Polybezier功能绘制图形 [英] Polybezier function Plotting a graph

查看:89
本文介绍了Polybezier功能绘制图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我正在使用预定义函数绘制MFC中的图形,即Polybezier函数,它可以获取多个点并允许您绘制曲线。基本上我需要它用于多线程应用程序,它在我们收到它时绘制点。下面是它的代码,请告诉我它有什么问题。



Hello,
I am using a pre-defined function for plotting graphs in MFC i.e. Polybezier function that takes in multiple points and allows you to draw a curve. Basically I need it for a multithreaded application that plots the points as and when we receive it. Below is the code for it, kindly please let me know what is wrong with it.

void CCurveDlg::DrawCurve(CDC& argDc)
{
   CDC* pDC =  &argDc;
   CBrush* pOldBrush = pDC->GetCurrentBrush();
   CPen* pOldPen = pDC->GetCurrentPen();

   CRect rectClient;
   m_GraphWindowCtrl.GetWindowRect(&rectClient);
   ScreenToClient(&rectClient); 

   CBrush brush;
   CBrush* pBrush;
   brush.CreateSolidBrush(RGB(0,255,0));  
   pBrush = pDC->SelectObject(&brush);

   CRect txtRectX,txtRectY;
   CPen pen;
   CPen* pPen;
   pen.CreatePen(PS_SOLID | PS_COSMETIC, 1, RGB(0,0,0));
   pPen = pDC->SelectObject(&pen);
   pDC->MoveTo(rectClient.TopLeft());
   CString tempStr;

   CPoint Pt;   
   Pt.x = rectClient.left + iSec;// iSec is just for updating it every second
   Pt.y = (rectClient.bottom - rectClient.top) - m_lStrainTotal/10000;

   if(rectClient.PtInRect(Pt))
      pDC->PolyBezier(&Pt, 20);

   iSec++;

   pDC->SelectObject(&pOldPen);
   pDC->SelectObject(&pOldBrush);
}





有关我哪里出错的建议吗?它没有绘制任何btw。



Any suggestions on where I am going wrong? It does not plot anything btw.

推荐答案

in
CPoint Pt;
...
pDC->PolyBezier(&Pt, 20);



你告诉PolyBezier你传递的是20个POINT结构的数组,但实际上只有一个分配并填充了Pt。



另外:

- 从不使用ScreenY / YMeter。 OffsetX / Y也是如此。

- 如果从代码中看不到您的坐标计算逻辑。只需使用您的调试器进行检查即可。

- 使用SaveDC / RestoreDC而不是手动保存/恢复所有设置,让您的生活更轻松。这样你可能不会忘记一个。


you are telling PolyBezier that you are passing an array of 20 POINT structures, but you actually have only a single one allocated and filled in Pt.

Also:
- ScreenY/YMeter are never used. So are OffsetX/Y.
- If your logic for coordinate calculation works can not be seen from the code. Just check it with your debugger.
- Make your life easier by using SaveDC / RestoreDC instead of saving / restoring all settings by hand. That way you are probably not going to forget one.


这篇关于Polybezier功能绘制图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆