使用GDI+画仪表表盘
Gdiplus::Bitmap * CSlaveView::GetPumpImage( float fMin,float fMax,float fValue,CString strUnit ){
const float PI=3.141592653;
if(fMin>fValue)
{
fMin=fValue;
}
if(fValue>fMax)
{
fMax=fValue;
}
int nWidth,nHeight;
nWidth=nHeight=200;
Gdiplus::Rect rect(0,0,nWidth,nHeight);
int nTable=5; // 大格
int nScale=5; // 每小段里面的小格
// 每段颜色
Gdiplus::Color TableColor[]=
{
Gdiplus::Color::Green,
Gdiplus::Color::Blue,
Gdiplus::Color::Cyan,
Gdiplus::Color::Yellow,
Gdiplus::Color::Red
};
// 张开的弧度
float fRadian=60;
// 同心圆半径
int nRadius[]=
{
200,
160,
90
};
// 圆心
Gdiplus::Point ptCenter(nWidth/2,nHeight+20);
// 刻度线长度
int nLongScal=15;
int nShortScal=10;
// 背景色
Gdiplus::Color bkColor=Gdiplus::Color::SkyBlue;
// 刻度字体,大小,颜色
Gdiplus::Color ScaleColor=Gdiplus::Color::Blue;
Gdiplus::REAL ScaleSize=10;
CString ScaleFont=_T("Times New Roman");
Gdiplus::Bitmap *pImage=new Gdiplus::Bitmap(nWidth,nHeight);
Graphics *pGraph=Graphics::FromImage(pImage);
Gdiplus::StringFormat format;
// 消除锯齿
format.SetAlignment( StringAlignmentCenter);
format.SetLineAlignment(StringAlignmentCenter);
pGraph->SetTextRenderingHint(TextRenderingHintAntiAlias);
pGraph->Clear(Gdiplus::Color::Transparent);
Gdiplus::Color LineColor=Gdiplus::Color::Chocolate;
Gdiplus::Pen LinePen(LineColor,1);
// 画三段弧
rect=Gdiplus::Rect(ptCenter.X-nRadius[0],ptCenter.Y-nRadius[0],2*nRadius[0],2*nRadius[0]);
pGraph->DrawArc(&LinePen,rect,180+(90-fRadian/2),fRadian);
rect=Gdiplus::Rect(ptCenter.X-nRadius[1],ptCenter.Y-nRadius[1],2*nRadius[1],2*nRadius[1]);
pGraph->DrawArc(&LinePen,rect,180+(90-fRadian/2),fRadian);
rect=Gdiplus::Rect(ptCenter.X-nRadius[2],ptCenter.Y-nRadius[2],2*nRadius[2],2*nRadius[2]);
pGraph->DrawArc(&LinePen,rect,180+(90-fRadian/2),fRadian);
// 标刻度
// 分段
for(int i=0;i<=nTable*nScale;i++)
{
Gdiplus::Point p1,p0;
double f0=((180-fRadian)/2+fRadian/(nTable*nScale)*i)/180*PI;
p1.X=ptCenter.X+nRadius[1]*cos(f0);
p1.Y=ptCenter.Y-nRadius[1]*sin(f0);
if(i%nTable==0)
{
{
p0.X=ptCenter.X+(nRadius[1]+nLongScal)*cos(f0);
p0.Y=ptCenter.Y-(nRadius[1]+nLongScal)*sin(f0);
CString str;
str.Format(_T("%.0f"),fMax-(fMax-fMin)/(nTable*nScale)*i);
// 获取文本所占的大小 www..zzzyk.com
CSize size=CGraphCurveView::GetOutPutTextSize(pGraph,str,ScaleFont,ScaleSize);
Gdiplus::RectF textrc;
textrc.X=p0.X-size.cx/2;
textrc.Y=p0.Y-size.cy;
textrc.Width=size.cx;
textrc.Height=size.cy;
pGraph->DrawString(
str,
-1,
&Gdiplus::Font(ScaleFont,ScaleSize),
textrc,
&format,
&Gdiplus::SolidBrush(ScaleColor)
);
Gdiplus::Point p2,p3;
int nGap=5;
p3.X=ptCenter.X+(
补充:软件开发 , Vc ,