求教C++图形处理的一些小问题
hl_cx 2012-03-09 01:13:38 本人模仿别人的代码,从数据库里读数据然后画了一条曲线图。画完发现图形是倒过来的。请问应该如何将图形正过来呢?
画布的大小是550,450.画图代码如下:
//连接数据库
ADOConn m_AdoConn;
m_AdoConn.OnInitADOConn();
//设置SELECT语句
_bstr_t vSQL;
vSQL = "select p_id%1024 as id,p_value from tb_pdatavalue where p_id%1024<=512 and p_id%1024<>0";
//执行SELECT语句
_RecordsetPtr m_pRecordset;
m_pRecordset = m_AdoConn.GetRecordSet(vSQL);
RECT fillrect;
_variant_t mo;
int xx, yy;
int yp = TrafficDrawRectangle.bottom;
int nLastMo=0,nLastID=0;
while( m_pRecordset->adoEOF == 0 ) //EOF判断是否到末尾
{
mo = m_pRecordset->GetCollect( "id" );
xx = atoi( (char *)_bstr_t(mo) );
mo = m_pRecordset->GetCollect( "p_value" );
yy = atoi( (char *)_bstr_t(mo) );
fillrect.bottom = yy - 1;
fillrect.top = yy;
fillrect.left = xx;
fillrect.right = xx + plotgranularity;
//以下代码是进行连线的代码
if( bFirstPoint )
{
nLastMo = yy;
nLastID = xx;
bFirstPoint = FALSE;
continue;
}
MemDC->MoveTo( nLastID, nLastMo );
MemDC->LineTo( xx, yy );
nLastMo = yy;
nLastID = xx;
m_pRecordset->MoveNext();
}
//断开与数据库的连接
m_AdoConn.ExitConnect();
请问MemDC->MoveTo()这里应该怎么改,才能将图形反转过来,主要就是因为画布的左上角坐标是(0,0)导致的?
另外我还有一个小问题,我在用开放函数的时候,发现结果是double,我怎么能把结果编程保留6位小数的浮点型呢?代码如下:
float modulo;
modulo = sqrt(xreal[i]*xreal[i] + ximag[i]*ximag[i]);