DrawRoundedRect doesn't work

Magick++ is an object-oriented C++ interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick++.
Locked
ap0c552
Posts: 5
Joined: 2020-03-18T13:47:44-07:00
Authentication code: 1152

DrawRoundedRect doesn't work

Post by ap0c552 »

I am am trying to draw a rounded rect.

I have the following code...

Code: Select all

	Magick::Image &i = w.GetVar(m_imgvar).ToImage();

	if (!m_has_radius) {
		i.draw( DrawableRectangle(m_left, m_top, m_right, m_bottom) );
		return;
	}

	int width = m_right - m_left;
	int height = m_bottom - m_top;
	double center_x = m_left + width/2;
	double center_y = m_left + height/2;

	i.draw( DrawableRoundRectangle(center_x, center_y, width, height , m_radius ,m_radius) );
If m_has_radius is false, DrawableRectangle is called. In this scenario the output image correctly contains the expected rectangle.

If m_has_radius is false, then DrawableRoundRectangle is called. In this scenario, the arguments provided are as expected, except the output image is empty. Nothing has been drawn.

Am I am potentially misinterpreting the parameters.

I tested with and 800x800 image with
center_x = 400
center_y = 400
height = 400
width = 400
corner_height = 4
corner_width = 4

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: DrawRoundedRect doesn't work

Post by snibgo »

ap0c552 wrote:double center_y = m_left + height/2;
Wrong.
snibgo's IM pages: im.snibgo.com

ap0c552
Posts: 5
Joined: 2020-03-18T13:47:44-07:00
Authentication code: 1152

Re: DrawRoundedRect doesn't work

Post by ap0c552 »

Good catch! Unfortunately for my input values (square rect being drawn in square image), this bug did not matter.

After fixing, the same issue persists.

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: DrawRoundedRect doesn't work

Post by snibgo »

From drawable.h, it seems the parameters are: double upperLeftX_, double upperLeftY_, double lowerRightX_, double lowerRightY_, double cornerWidth_, double cornerHeight_

But you have different parameters. Maybe they are okay; I don't know.
snibgo's IM pages: im.snibgo.com

ap0c552
Posts: 5
Joined: 2020-03-18T13:47:44-07:00
Authentication code: 1152

Re: DrawRoundedRect doesn't work

Post by ap0c552 »

I am using an older version of imagemagick, which explains the difference in method signature.

ap0c552
Posts: 5
Joined: 2020-03-18T13:47:44-07:00
Authentication code: 1152

Re: DrawRoundedRect doesn't work

Post by ap0c552 »

Turns out the the parameters DrawRoundedRect take are indeed double upperLeftX_, double upperLeftY_, double lowerRightX_, double lowerRightY_, double cornerWidth_, double cornerHeight_ . But for some reason, they are named differently in the version of Drawable.h that I am using. So either there was a bug in past versions, or someone working in my code base in the past took it upon themselves to incorrectly rename the parameters. Either way, mystery solved.

Locked