首页 > 代码库 > GDI+ 画渐变色环

GDI+ 画渐变色环



在onpaint() 函数中加入如下代码,本次利用DrawArc来实现。

#define PI 3.1415926
int angle=360;
int x=(rect.Width()-300)/2;
int y=190;
int width=300;
int hight=300;
int wide=34;

graphics.SetSmoothingMode(SmoothingModeAntiAlias);//抗锯齿

for(float i = 0.0; i < PI; i += (float)((float)PI/360)) {
float h,tc, tx;
float tr,tg,tb;
tr=tg=tb=1;
h = i*1.9;
tc = 1;
tx = tc * (1 - abs(fmod(h,2) - 1));
if(0 <= h && h < 1) {       tr = tc;   tg = tx;    tb = 0;   }
else if(1 <= h && h < 2) {  tr = tx;   tg = tc;    tb = 0;   }
else if(2 <= h && h < 3) {  tr = 0;    tg = tc;    tb = tx;  }
else if(3 <= h && h < 4) {  tr = 0;    tg = tx;    tb = tc;  }
else if(4 <= h && h < 5) {  tr = tx;   tg = 0;     tb = tc;  }
else if(5 <= h && h < 6) {  tr = tc;   tg = 0;     tb = tx;  }
tr = tr * 255;
tg = tg * 255;
tb = tb * 255;
Gdiplus::Pen pen(Color (255, (byte)tr, (byte)tg,(byte)tb ),wide);  
angle-=1;
graphics.DrawArc(&pen, x, y, width, hight, angle ,2);
}