关于GDI+ 画圆弧的问题

qq_32761915 2017-07-28 10:46:35
MSDN上面的例子是:
VOID Example_DrawArc(HDC hdc)
{
Graphics graphics(hdc);

// Set up the arc.
Pen redPen(Color::Red, 3);
Rect ellipseRect(0, 0, 200, 100);
REAL startAngle = 0.0f;
REAL sweepAngle = 90.0f;

// Draw the arc.
graphics.DrawArc(&redPen, ellipseRect, startAngle, sweepAngle);
}

但,如果我想以界面的四个顶点(左上角、右上角、左下角、右下角)画圆弧(圆形),那么这个区域需要怎么设置?
...全文
463 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2017-07-28
  • 打赏
  • 举报
回复
为什么不能设置为负数?试试不就知道了。 不要迷信书、考题、老师、回帖; 要迷信CPU、编译器、调试器、运行结果。 并请结合“盲人摸太阳”和“驾船出海时一定只带一个指南针。”加以理解。 任何理论、权威、传说、真理、标准、解释、想象、知识……都比不上摆在眼前的事实!
qq_32761915 2017-07-28
  • 打赏
  • 举报
回复
引用 1 楼 zhao4zhong1 的回复:
Syntax

Status DrawArc(          const Pen *pen,
    const Rect &rect,
    REAL startAngle,
    REAL sweepAngle
);
Parameters

pen
[in] Pointer to a pen that is used to draw the arc. 
rect
[in] Reference to the rectangle that bounds the ellipse that contains the arc. 
startAngle
[in] Real number that specifies the angle between the x-axis and the starting point of the arc. 
sweepAngle
[in] Real number that specifies the angle between the starting and ending points of the arc.


Syntax

Status DrawArc(          const Pen *pen,
    const RectF &rect,
    REAL startAngle,
    REAL sweepAngle
);
Parameters

pen
[in] Pointer to a pen that is used to draw the arc. 
rect
[in] Reference to the rectangle that bounds the ellipse that contains the arc. 
startAngle
[in] Real number that specifies the angle between the x-axis and the starting point of the arc. 
sweepAngle
[in] Real number that specifies the angle between the starting and ending points of the arc. 
Return Value

Syntax

Status DrawArc(          const Pen *pen,
    REAL x,
    REAL y,
    REAL width,
    REAL height,
    REAL startAngle,
    REAL sweepAngle
);
Parameters

pen
[in] Pointer to a pen that is used to draw the arc. 
x
[in] Real number that specifies the x-coordinate of the upper-left corner of the bounding rectangle for the ellipse that contains the arc. 
y
[in] Real number that specifies the y-coordinate of the upper-left corner of the bounding rectangle for the ellipse that contains the arc. 
width
[in] Real number that specifies the width of the ellipse that contains the arc. 
height
[in] Real number that specifies the height of the ellipse that contains the arc. 
startAngle
[in] Real number that specifies the angle between the x-axis and the starting point of the arc. 
sweepAngle
[in] Real number that specifies the angle between the starting and ending points of the arc.


Syntax

Status DrawArc(          const Pen *pen,
    INT x,
    INT y,
    INT width,
    INT height,
    REAL startAngle,
    REAL sweepAngle
);
Parameters

pen
[in] Pointer to a pen that is used to draw the arc. 
x
[in] Integer that specifies the x-coordinate of the upper-left corner of the bounding rectangle for the ellipse that contains the arc. 
y
[in] Integer that specifies the y-coordinate of the upper-left corner of the bounding rectangle for the ellipse that contains the arc. 
width
[in] Integer that specifies the width of the ellipse that contains the arc. 
height
[in] Integer that specifies the height of the ellipse that contains the arc. 
startAngle
[in] Real number that specifies the angle between the x-axis and the starting point of the arc. 
sweepAngle
[in] Real number that specifies the angle between the starting and ending points of the arc. 

对呀……它所包含的参数,都是画圆的区域,或者区域的左上角。我现在是想,以左上角作为圆心来画圆弧……那,画圆参数左上角的位置,我总不能设置为负数吧。
赵4老师 2017-07-28
  • 打赏
  • 举报
回复
Syntax

Status DrawArc(          const Pen *pen,
    const Rect &rect,
    REAL startAngle,
    REAL sweepAngle
);
Parameters

pen
[in] Pointer to a pen that is used to draw the arc. 
rect
[in] Reference to the rectangle that bounds the ellipse that contains the arc. 
startAngle
[in] Real number that specifies the angle between the x-axis and the starting point of the arc. 
sweepAngle
[in] Real number that specifies the angle between the starting and ending points of the arc.


Syntax

Status DrawArc(          const Pen *pen,
    const RectF &rect,
    REAL startAngle,
    REAL sweepAngle
);
Parameters

pen
[in] Pointer to a pen that is used to draw the arc. 
rect
[in] Reference to the rectangle that bounds the ellipse that contains the arc. 
startAngle
[in] Real number that specifies the angle between the x-axis and the starting point of the arc. 
sweepAngle
[in] Real number that specifies the angle between the starting and ending points of the arc. 
Return Value

Syntax

Status DrawArc(          const Pen *pen,
    REAL x,
    REAL y,
    REAL width,
    REAL height,
    REAL startAngle,
    REAL sweepAngle
);
Parameters

pen
[in] Pointer to a pen that is used to draw the arc. 
x
[in] Real number that specifies the x-coordinate of the upper-left corner of the bounding rectangle for the ellipse that contains the arc. 
y
[in] Real number that specifies the y-coordinate of the upper-left corner of the bounding rectangle for the ellipse that contains the arc. 
width
[in] Real number that specifies the width of the ellipse that contains the arc. 
height
[in] Real number that specifies the height of the ellipse that contains the arc. 
startAngle
[in] Real number that specifies the angle between the x-axis and the starting point of the arc. 
sweepAngle
[in] Real number that specifies the angle between the starting and ending points of the arc.


Syntax

Status DrawArc(          const Pen *pen,
    INT x,
    INT y,
    INT width,
    INT height,
    REAL startAngle,
    REAL sweepAngle
);
Parameters

pen
[in] Pointer to a pen that is used to draw the arc. 
x
[in] Integer that specifies the x-coordinate of the upper-left corner of the bounding rectangle for the ellipse that contains the arc. 
y
[in] Integer that specifies the y-coordinate of the upper-left corner of the bounding rectangle for the ellipse that contains the arc. 
width
[in] Integer that specifies the width of the ellipse that contains the arc. 
height
[in] Integer that specifies the height of the ellipse that contains the arc. 
startAngle
[in] Real number that specifies the angle between the x-axis and the starting point of the arc. 
sweepAngle
[in] Real number that specifies the angle between the starting and ending points of the arc. 

qq_32761915 2017-07-28
  • 打赏
  • 举报
回复

我研究研究怎么样才能得利我想要的效果。
//GDI+
Rect nRect(Front_Left.x,Front_Left.y,m_rc_FrontArea.Width(),m_rc_FrontArea.Height());
Graphics graphics(pDc->m_hDC);
graphics.SetPageUnit(UnitPixel);
graphics.SetSmoothingMode(SmoothingModeAntiAlias);
graphics.SetClip(nRect);
graphics.TranslateTransform(0,0);
Pen pen(Color::Red, 1);
for (i=0;i<10;i++)
{

if (i>7 || i<3)
{
continue;
}
line =(0.1*i*lineL);
startpoint.x = OriginFront_Left.x + line*cos(fstartangle*pi/180);
startpoint.y = OriginFront_Left.y + line*sin(fstartangle*pi/180);
startpoint = RectangularcoordinateToOrigin(startpoint,Front_Left);
CPoint Opoint = RectangularcoordinateToOrigin(OriginFront_Left,Front_Left);
pDc->MoveTo(startpoint);
pDc->SetBrushOrg(startpoint);
//pDc->SetArcDirection(AD_CLOCKWISE);
//pDc->AngleArc(Opoint.x,Opoint.y,line,fstartangle,m_f_Arc_Angle);
//pDc->SetArcDirection(AD_COUNTERCLOCKWISE);
graphics.DrawArc(&pen,m_rc_FrontArea.left,m_rc_FrontArea.top,80,80,0,360);
}
赵4老师 2017-07-28
  • 打赏
  • 举报
回复
#pragma comment(lib,"user32")
#pragma comment(lib,"gdi32")
#pragma comment(lib, "gdiplus.lib")
#include <windows.h>
#include <gdiplus.h>
using namespace Gdiplus;
VOID OnPaint(HDC hdc) {
   Graphics     graphics(hdc);
   Pen redPen(Color::Red, 3);
   Rect ellipseRect;
   REAL startAngle;
   REAL sweepAngle;

   graphics.SetSmoothingMode(SmoothingModeHighQuality);

   ellipseRect=Rect(0, 0, 100, 100);
   startAngle = 0.0f;
   sweepAngle = 45.0f;
   graphics.DrawArc(&redPen, ellipseRect, startAngle, sweepAngle);

   ellipseRect=Rect(150, 0, 100, 100);
   startAngle = 180.0f;
   sweepAngle = -45.0f;
   graphics.DrawArc(&redPen, ellipseRect, startAngle, sweepAngle);

   ellipseRect=Rect(0, 150, 100, 100);
   startAngle = 0.0f;
   sweepAngle = -45.0f;
   graphics.DrawArc(&redPen, ellipseRect, startAngle, sweepAngle);

   ellipseRect=Rect(150, 150, 100, 100);
   startAngle = 180.0f;
   sweepAngle = 45.0f;
   graphics.DrawArc(&redPen, ellipseRect, startAngle, sweepAngle);
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
   HDC          hdc;
   PAINTSTRUCT  ps;

   switch(message) {
   case WM_PAINT:
      hdc = BeginPaint(hWnd, &ps);
      OnPaint(hdc);
      EndPaint(hWnd, &ps);
      return 0;
   case WM_DESTROY:
      PostQuitMessage(0);
      return 0;
   default:
      return DefWindowProc(hWnd, message, wParam, lParam);
   }
}
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, PSTR, INT iCmdShow) {
   HWND                hWnd;
   MSG                 msg;
   WNDCLASS            wndClass;
   GdiplusStartupInput gdiplusStartupInput;
   ULONG_PTR           gdiplusToken;

   GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

   wndClass.style          = CS_HREDRAW | CS_VREDRAW;
   wndClass.lpfnWndProc    = WndProc;
   wndClass.cbClsExtra     = 0;
   wndClass.cbWndExtra     = 0;
   wndClass.hInstance      = hInstance;
   wndClass.hIcon          = LoadIcon(NULL, IDI_APPLICATION);
   wndClass.hCursor        = LoadCursor(NULL, IDC_ARROW);
   wndClass.hbrBackground  = (HBRUSH)GetStockObject(WHITE_BRUSH);
   wndClass.lpszMenuName   = NULL;
   wndClass.lpszClassName  = TEXT("GettingStarted");

   RegisterClass(&wndClass);

   hWnd = CreateWindow(
      TEXT("GettingStarted"),   // window class name
      TEXT("Getting Started"),  // window caption
      WS_OVERLAPPEDWINDOW,      // window style
      CW_USEDEFAULT,            // initial x position
      CW_USEDEFAULT,            // initial y position
      CW_USEDEFAULT,            // initial x size
      CW_USEDEFAULT,            // initial y size
      NULL,                     // parent window handle
      NULL,                     // window menu handle
      hInstance,                // program instance handle
      NULL);                    // creation parameters

   ShowWindow(hWnd, iCmdShow);
   UpdateWindow(hWnd);

   while(GetMessage(&msg, NULL, 0, 0)) {
      TranslateMessage(&msg);
      DispatchMessage(&msg);
   }

   GdiplusShutdown(gdiplusToken);

   return 0;
}
qq_32761915 2017-07-28
  • 打赏
  • 举报
回复
引用 9 楼 zhao4zhong1 的回复:
建议使用纯GDI去锯齿试试。 仅供参考,尽管是VB6:
Const STRETCH_HALFTONE = 4
Private Declare Function SetStretchBltMode Lib "gdi32" (ByVal hdc As Long, ByVal nStretchMode As Long) As Long
Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
Dim sDisplay As String
Private Sub Form_Load()
    sDisplay = "字体反锯齿前"
    pDest.Cls
    pDest.Print
    pDest.Print sDisplay

    sDisplay = "字体反锯齿后"
    pFont.Cls
    pFont.Print sDisplay
    SetStretchBltMode pDest.hdc, STRETCH_HALFTONE
    StretchBlt pDest.hdc, 0, 0, pDest.TextWidth(sDisplay), pDest.TextHeight(sDisplay), pFont.hdc, 0, 0, pFont.TextWidth(sDisplay), pFont.TextHeight(sDisplay), vbSrcCopy
End Sub
好的 我试试
赵4老师 2017-07-28
  • 打赏
  • 举报
回复
建议使用纯GDI去锯齿试试。
仅供参考,尽管是VB6:
Const STRETCH_HALFTONE = 4
Private Declare Function SetStretchBltMode Lib "gdi32" (ByVal hdc As Long, ByVal nStretchMode As Long) As Long
Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
Dim sDisplay As String
Private Sub Form_Load()
sDisplay = "字体反锯齿前"
pDest.Cls
pDest.Print
pDest.Print sDisplay

sDisplay = "字体反锯齿后"
pFont.Cls
pFont.Print sDisplay
SetStretchBltMode pDest.hdc, STRETCH_HALFTONE
StretchBlt pDest.hdc, 0, 0, pDest.TextWidth(sDisplay), pDest.TextHeight(sDisplay), pFont.hdc, 0, 0, pFont.TextWidth(sDisplay), pFont.TextHeight(sDisplay), vbSrcCopy
End Sub

qq_32761915 2017-07-28
  • 打赏
  • 举报
回复


终于可以上传了
qq_32761915 2017-07-28
  • 打赏
  • 举报
回复
引用 6 楼 zhao4zhong1 的回复:
你使用了不够新版的gdiplus.dll ?

呃,图片传不上来。
for (i=0;i<10;i++)
{
if (i>7 || i<3)
{
continue;
}
line =(0.1*i*lineL);
startpoint.x = OriginFront_Left.x + line*cos(fstartangle*pi/180);
startpoint.y = OriginFront_Left.y + line*sin(fstartangle*pi/180);
startpoint = RectangularcoordinateToOrigin(startpoint,Front_Left);
CPoint Opoint = RectangularcoordinateToOrigin(OriginFront_Left,Front_Left);
pDc->MoveTo(startpoint);
pDc->SetArcDirection(AD_CLOCKWISE);
pDc->AngleArc(Opoint.x,Opoint.y,line,fstartangle,m_f_Arc_Angle);
pDc->SetArcDirection(AD_COUNTERCLOCKWISE);
// graphics.DrawArc(&pen,Front_Left.x,Front_Left.y,50,50,0,720);
}

我这用的是GDI画的,弧线锯齿感很强。注释部分是GDI+,第二、第三个参数设置负数的话,曲线出不来。如果我用常量去测试,是可以画出来。我现在是想消除GDI画出来的锯齿。曲线的半径会有一些变化,通过这个变化来绘制多条同心圆的圆弧。我现在疑惑,GDI+它怎么没有设置同心圆这个说法呢?反倒是需要设置一个矩形区域。
赵4老师 2017-07-28
  • 打赏
  • 举报
回复
你使用了不够新版的gdiplus.dll ?
赵4老师 2017-07-28
  • 打赏
  • 举报
回复
把起始终止角度反过来再试试?
qq_32761915 2017-07-28
  • 打赏
  • 举报
回复
引用 3 楼 zhao4zhong1 的回复:
为什么不能设置为负数?试试不就知道了。 不要迷信书、考题、老师、回帖; 要迷信CPU、编译器、调试器、运行结果。 并请结合“盲人摸太阳”和“驾船出海时一定只带一个指南针。”加以理解。 任何理论、权威、传说、真理、标准、解释、想象、知识……都比不上摆在眼前的事实!
其实也试过,结果是曲线出不来……

19,468

社区成员

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

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