Я пытаюсь нарисовать скругленный прямоугольник со сглаженными углами, однако весь прямоугольник подвергается сглаживанию, в результате чего края прямоугольника становятся размытыми. Я бы хотел, чтобы сглаживались только закругленные углы, чтобы стороны прямоугольника были четко определены.
[img]https:/ /i.sstatic.net/rEAT0uuk.png[/img]
Приведенный ниже код создает выходные данные «Только линия» и «Только заливка», но как я могу получить что-то, что выглядит ближе к ожидаемому изображению на крайний правый? (создано вручную в MS Paint)
void GetRoundRectPath2(GraphicsPath* pPath, Rect r, int dia)
{
// diameter can't exceed width or height
if (dia > r.Width) dia = r.Width;
if (dia > r.Height) dia = r.Height;
// define a corner
Rect Corner(r.X, r.Y, dia, dia);
// begin path
pPath->Reset();
// top left
pPath->AddArc(Corner, 180, 90);
// tweak needed for radius of 10 (dia of 20)
if (dia == 20)
{
Corner.Width += 1;
Corner.Height += 1;
r.Width -= 1; r.Height -= 1;
}
// top right
Corner.X += (r.Width - dia - 1);
pPath->AddArc(Corner, 270, 90);
// bottom right
Corner.Y += (r.Height - dia - 1);
pPath->AddArc(Corner, 0, 90);
// bottom left
Corner.X -= (r.Width - dia - 1);
pPath->AddArc(Corner, 90, 90);
// end path
pPath->CloseFigure();
}
void FillRoundRect2(Graphics* pGraphics, Brush* pBrush, Rect r, Color border, int radius)
{
int dia = 2 * radius;
// set to pixel mode
int oldPageUnit = pGraphics->SetPageUnit(UnitPixel);
// define the pen
Pen pen(border, 1);
pen.SetAlignment(PenAlignmentCenter);
// get the corner path
GraphicsPath path;
// get path
GetRoundRectPath2(&path, r, dia);
// fill
pGraphics->FillPath(pBrush, &path);
// draw the border last so it will be on top
pGraphics->DrawPath(&pen, &path);
// restore page unit
pGraphics->SetPageUnit((Unit)oldPageUnit);
}
Graphics graphics(dc);
graphics.SetSmoothingMode(SmoothingModeAntiAlias);
// Line only
SolidBrush sbrA(Gdiplus::Color(0,255,0,0)); // Full Transparent
FillRoundRect2(&graphics, &sbrA, Gdiplus::Rect(10, 10, 40, 40), Gdiplus::Color(50, 255, 0, 0), 5);
// Fill only
SolidBrush sbr(Gdiplus::Color(50, 255, 0, 0));
FillRoundRect2(&graphics, &sbr, Gdiplus::Rect(10, 10, 40, 40), Gdiplus::Color(0, 255, 0, 0), 5);
Подробнее здесь: https://stackoverflow.com/questions/785 ... ased-using
Как нарисовать закругленный заполненный прямоугольник со сглаженными только углами с помощью GDI+? ⇐ C++
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Многострочный заполненный текст с внешними и внутренними закругленными углами в CSS
Anonymous » » в форуме CSS - 0 Ответы
- 19 Просмотры
-
Последнее сообщение Anonymous
-