anand
anand

Reputation: 11339

Rounded edges with RoundRect are not smooth

rounded rectaangle I am drawing a rounded corner rectangle using RoundRect windows API.

RoundRect(hdc,0,0,100,100,4,4);

Here I am drawing rectangle with rounded corner width and height = 4 px.

After that I want to fill the rounded rectangle. For that I am creating rectangular region using

CreateRoundRectRgn

and then calling FillRgn API.

Problem is that after filling I can see fill color outside rounded corners also. Since I am creating rounded region, filling should only be inside that region.

Any ideas why its going outside rounded rectangle?

Upvotes: 1

Views: 2359

Answers (1)

arx
arx

Reputation: 16906

RoundRect already fills the rectangle using the current brush. Just use SelectObject to select the brush you want.

Which makes the following observations somewhat redundant. RoundRect and CreateRoundRectRgn interpret the coordinates differently. RoundRect's coordinates are inclusive but CreateRoundRectRgn's are exclusive at the bottom-right (so you have to add one to the bottom-right coordinates in the latter case).

And since Windows doesn't provide a function to get a region corresponding to the interior of a rounded rectangle, you'll never get pixel-perfect accuracy if you fill it yourself (the interior of a rounded rectangle is not the same as a slightly smaller rounded rectangle).

Upvotes: 4

Related Questions