VC怎么画图,如下效果,在线求助!!

dvj131415 2014-10-24 12:14:56
想画一个渐变曲线,颜色渐变,但作不出来,望大神提点!!
...全文
326 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
dvj131415 2014-10-29
  • 打赏
  • 举报
回复
引用 12 楼 schlafenhamster 的回复:

void CGradientArcDlg::HLSGradientTorus(HDC hDC, int OrigX, int OrigY, int InnerR, int OuterR,
						  COLORREF cStart, COLORREF cEnd, int Degree)
{
	KColor c0(cStart); c0.ToHLS();
	KColor c1(cEnd);   c1.ToHLS();

	Degree *=10;
	for (int i=0; i<Degree; i++)
	{
		KColor c;

		c.hue        = ( c0.hue       * (Degree-1-i) + c1.hue       * i ) / (Degree-1);
		c.lightness  = ( c0.lightness * (Degree-1-i) + c1.lightness * i ) / (Degree-1);
		c.saturation = ( c0.saturation* (Degree-1-i) + c1.saturation* i ) / (Degree-1);
		c.ToRGB();

#if 0
		HBRUSH hBrush = CreateSolidBrush(c.GetColorRef());
		RECT rect = { x0+i*(x1-x0)/nPart,     y0, 
					  x0+(i+1)*(x1-x0)/nPart, y1 }; 
		FillRect(hDC, & rect, hBrush);
		DeleteObject(hBrush);
#else
		HPEN hpen=CreatePen(PS_SOLID,1,c.GetColorRef());
		HPEN old=(HPEN)SelectObject(hDC,hpen);
		double Ix=OrigX-InnerR*cos(i*3.1415926/Degree);
		double Iy=OrigY-InnerR*sin(i*3.1415926/Degree);
		double Ox=OrigX-OuterR*cos(i*3.1415926/Degree);
		double Oy=OrigY-OuterR*sin(i*3.1415926/Degree);
		MoveToEx(hDC,(int)(Ix+0.5),(int)(Iy+0.5),0);
		LineTo(hDC,(int)(Ox+0.5),(int)(Oy+0.5));
		SelectObject(hDC,old);
		DeleteObject(hpen);
#endif
	}
}

void CGradientArcDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CPaintDC dc(this); // device context for painting
		HLSGradientTorus(dc.m_hDC, 350, 250, 100, 108, RGB(0,255,0), RGB(255,0,0), 180);
//		CDialog::OnPaint();
	}
}

需要袁锋的 color.h 和 color.cpp
谢谢,要的就是这种效果!
大树学长 2014-10-26
  • 打赏
  • 举报
回复
弧线贴图吧 背景透明 其余的绘图 怎么方便怎么来
schlafenhamster 2014-10-25
  • 打赏
  • 举报
回复

void CGradientArcDlg::HLSGradientTorus(HDC hDC, int OrigX, int OrigY, int InnerR, int OuterR,
COLORREF cStart, COLORREF cEnd, int Degree)
{
KColor c0(cStart); c0.ToHLS();
KColor c1(cEnd); c1.ToHLS();

Degree *=10;
for (int i=0; i<Degree; i++)
{
KColor c;

c.hue = ( c0.hue * (Degree-1-i) + c1.hue * i ) / (Degree-1);
c.lightness = ( c0.lightness * (Degree-1-i) + c1.lightness * i ) / (Degree-1);
c.saturation = ( c0.saturation* (Degree-1-i) + c1.saturation* i ) / (Degree-1);
c.ToRGB();

#if 0
HBRUSH hBrush = CreateSolidBrush(c.GetColorRef());
RECT rect = { x0+i*(x1-x0)/nPart, y0,
x0+(i+1)*(x1-x0)/nPart, y1 };
FillRect(hDC, & rect, hBrush);
DeleteObject(hBrush);
#else
HPEN hpen=CreatePen(PS_SOLID,1,c.GetColorRef());
HPEN old=(HPEN)SelectObject(hDC,hpen);
double Ix=OrigX-InnerR*cos(i*3.1415926/Degree);
double Iy=OrigY-InnerR*sin(i*3.1415926/Degree);
double Ox=OrigX-OuterR*cos(i*3.1415926/Degree);
double Oy=OrigY-OuterR*sin(i*3.1415926/Degree);
MoveToEx(hDC,(int)(Ix+0.5),(int)(Iy+0.5),0);
LineTo(hDC,(int)(Ox+0.5),(int)(Oy+0.5));
SelectObject(hDC,old);
DeleteObject(hpen);
#endif
}
}

void CGradientArcDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting

SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;

// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CPaintDC dc(this); // device context for painting
HLSGradientTorus(dc.m_hDC, 350, 250, 100, 108, RGB(0,255,0), RGB(255,0,0), 180);
// CDialog::OnPaint();
}
}



需要袁锋的 color.h 和 color.cpp
dvj131415 2014-10-24
  • 打赏
  • 举报
回复
应该不是,点旁边的按钮可以动的!
dvj131415 2014-10-24
  • 打赏
  • 举报
回复
是用打点的方式画吗,好像是直接在对话框上面画的,最近要做个类似的模块,想了半天没想出来!
schlafenhamster 2014-10-24
  • 打赏
  • 举报
回复
是 贴图的 吧
快乐鹦鹉 2014-10-24
  • 打赏
  • 举报
回复
你这个扇形是用一堆的线条形成的,每条线使用不同的颜色,按照渐变的规律
dvj131415 2014-10-24
  • 打赏
  • 举报
回复
左边的那个输出功率 怎么画
快乐鹦鹉 2014-10-24
  • 打赏
  • 举报
回复
就是一条线么?多宽?渐变有很多样式,你想哪一种?
dvj131415 2014-10-24
  • 打赏
  • 举报
回复
schlafenhamster 2014-10-24
  • 打赏
  • 举报
回复
按你的图 要 绿-黄-红 渐变。(即 HLS 渐变) 参考 “window图形编程 袁锋” 第 9 章, 搜索 HLSGradientRectangle 。 要 改成 MoveTo LineTo
赵4老师 2014-10-24
  • 打赏
  • 举报
回复
Creating a Linear Gradient -------------------------------------------------------------------------------- GDI+ provides horizontal, vertical, and diagonal linear gradients. By default, the color in a linear gradient changes uniformly. However, you can customize a linear gradient so that the color changes in a non-uniform fashion. Horizontal Linear Gradients Customizing Linear Gradients Diagonal Linear Gradients Horizontal Linear Gradients The following example uses a horizontal linear gradient brush to fill a line, an ellipse, and a rectangle: LinearGradientBrush linGrBrush( Point(0, 10), Point(200, 10), Color(255, 255, 0, 0), // opaque red Color(255, 0, 0, 255)); // opaque blue Pen pen(&linGrBrush); graphics.DrawLine(&pen, 0, 10, 200, 10); graphics.FillEllipse(&linGrBrush, 0, 30, 200, 100); graphics.FillRectangle(&linGrBrush, 0, 155, 500, 30); The LinearGradientBrush constructor receives four arguments: two points and two colors. The first point (0, 10) is associated with the first color (red), and the second point (200, 10) is associated with the second color (blue). As you would expect, the line drawn from (0, 10) to (200, 10) changes gradually from red to blue. The 10s in the points (50, 10) and (200, 10) are not important. What's important is that the two points have the same second coordinate — the line connecting them is horizontal. The ellipse and the rectangle also change gradually from red to blue as the horizontal coordinate goes from 0 to 200. The following illustration shows the line, the ellipse, and the rectangle. Note that the color gradient repeats itself as the horizontal coordinate increases beyond 200. Customizing Linear Gradients In the preceding example, the color components change linearly as you move from a horizontal coordinate of 0 to a horizontal coordinate of 200. For example, a point whose first coordinate is halfway between 0 and 200 will have a blue component that is halfway between 0 and 255. GDI+ allows you to adjust the way a color varies from one edge of a gradient to the other. Suppose you want to create a gradient brush that changes from black to red according to the following table. Horizontal coordinate RGB components 0 (0, 0, 0) 40 (128, 0, 0) 200 (255, 0, 0) Note that the red component is at half intensity when the horizontal coordinate is only 20 percent of the way from 0 to 200. The following example calls the SetBlend method of a LinearGradientBrush object to associate three relative intensities with three relative positions. As in the preceding table, a relative intensity of 0.5 is associated with a relative position of 0.2. The code fills an ellipse and a rectangle with the gradient brush. Hide Example LinearGradientBrush linGrBrush( Point(0, 10), Point(200, 10), Color(255, 0, 0, 0), // opaque black Color(255, 255, 0, 0)); // opaque red REAL relativeIntensities[] = {0.0f, 0.5f, 1.0f}; REAL relativePositions[] = {0.0f, 0.2f, 1.0f}; linGrBrush.SetBlend(relativeIntensities, relativePositions, 3); graphics.FillEllipse(&linGrBrush, 0, 30, 200, 100); graphics.FillRectangle(&linGrBrush, 0, 155, 500, 30);
快乐鹦鹉 2014-10-24
  • 打赏
  • 举报
回复
不是贴图,也不是打点,而是画线条。沿着弧线方向,纵向不断地画不同颜色的线条。
dvj131415 2014-10-24
  • 打赏
  • 举报
回复
引用 4 楼 happyparrot 的回复:
你这个扇形是用一堆的线条形成的,每条线使用不同的颜色,按照渐变的规律
这个扇形是怎么画出来的,打点的方式吗

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧