문제

나는 그리기하려고 노력했다 고리 (두께가있는 고리) 투명한 구멍과 C#의 그라디언트 림이 거의 성공하지 못했습니다. 누구 든지이 작업을 수행하는 방법에 대한 제안이 있습니까?

여기 좋은 일이 있습니다 유틸리티를 혼합하십시오

Bluemonkmn 덕분에 최종 결과는 다음과 같습니다

 Rectangle GetSquareRec(double radius, int x, int y)
    {
        double r = radius;
        double side = Math.Sqrt(Math.Pow(r, 2) / 2);
        Rectangle rec = new Rectangle(x - ((int)side), y - ((int)side), (int)(side * 2) + x, (int)(side * 2) + y);

        return rec;
    }
    void Form1_Paint(object sender, PaintEventArgs e)
    {


        Graphics gTarget = e.Graphics;
        gTarget.SmoothingMode = SmoothingMode.AntiAlias;


        GraphicsPath pTemp = new GraphicsPath();

        Rectangle r = GetSquareRec(200, 225, 225);
        pTemp.AddEllipse(r);
        pTemp.AddEllipse(GetSquareRec(50, 225, 225));

        Color[] colors = new Color[5];
        colors[0] = Color.FromArgb(192, 192, 192);
        colors[1] = Color.FromArgb(105, 0, 0);
        colors[2] = Color.FromArgb(169, 169, 169);
        colors[3] = Color.FromArgb(0, 0, 0);
        colors[4] = Color.FromArgb(0, 0, 0);

        float[] positions = new float[5];
        positions[0] = 0f;
        positions[1] = 0.1f;
        positions[2] = 0.35f;
        positions[3] = 0.5f;
        positions[4] = 1f;

        ColorBlend Cb = new ColorBlend();
        Cb.Colors = colors;
        Cb.Positions = positions;

        PathGradientBrush pgb = new PathGradientBrush(pTemp);
        pgb.InterpolationColors = Cb;
        pgb.CenterPoint = new PointF(r.X + (r.Width / 2), r.Y + (r.Height / 2));
        gTarget.FillPath(pgb, pTemp);

    }

http://www.freeimagehosting.net/uploads/th.515733e62e.jpg

도움이 되었습니까?

해결책

이것이 내가 어떻게했는지입니다 게임 개발 키트를 스크롤합니다:

pTemp = new GraphicsPath();
pTemp.AddEllipse(Start.X, Start.Y, End.X - Start.X, End.Y - Start.Y);
pTemp.AddEllipse((Start.X * 3 + End.X) / 4f,
                 (Start.Y * 3 + End.Y) / 4f,
                 (End.X - Start.X) / 2f,
                 (End.Y - Start.Y) / 2f);
PathGradientBrush pgb = new PathGradientBrush(pTemp);
Blend b = new Blend();
b.Factors = new float[] { 0, 1, 1 };
b.Positions = new float[] { 0, .5F, 1 };
pgb.Blend = b;
pgb.CenterColor = ((SolidBrush)CurrentBrush).Color;
pgb.SurroundColors = new Color[] {CurrentPen.Color};
gTarget.FillPath(pgb, pTemp);
pgb.Dispose();
pTemp.Dispose();

annulus screenshot
(원천: enigmadream.com)

원래 구멍을 배제하기 위해 그라디언트를 확장하기에 충분히 똑똑하지 않았기 때문에이 샘플의 원래 sgdk 코드를 편집했습니다.

오히려 다음과 같은 그라디언트를 볼 수 있다면 다음과 같습니다.

alt text
(원천: enigmadream.com)

그런 다음 블렌드 코드를 다음과 같이 보이게 변경하십시오.

Blend blend = new Blend();
blend.Factors = new float[] { 0, 1, 0, 0 };
blend.Positions = new float[] { 0, 0.25F, .5F, 1 };
pgb.Blend = blend;

다른 팁

Graphics.DrawArc 결합 된 두 번의 호출을 사용하여 ANGULUS의 상단 및 하단 및 왼쪽 부분을 한 번에 한 부분 씩 그려냅니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top