Skip to main content
shark
Associate III
June 8, 2020
Question

How to draw a rectangle with round corner

  • June 8, 2020
  • 9 replies
  • 1536 views

How to draw a rectangle with round corner.

This topic has been closed for replies.

9 replies

Alexandre RENOUX
Visitor II
June 9, 2020

Hello,

You can do that by using an image editor (paint.net, photoshop, gimp) -> create a rectangle with round corners -> save the image as png (so that alpha is included) -> import this image in your touchGFX project and use the Image widget to add it to your screen.

/Alexandre

shark
sharkAuthor
Associate III
June 9, 2020

Sorry, I need it at run time by coding.

Alexandre RENOUX
Visitor II
June 9, 2020

Hello,

You can display the rectangle at run time whenever you want in the app. Just do rectangleImage.setVisible(true) when needed.

What do you want to do ?

/Alexandre

shark
sharkAuthor
Associate III
June 9, 2020

Sorry, I need to draw rectangle with 4 round corner, with different size specified at run time.

Alexandre RENOUX
Visitor II
June 9, 2020

Hello,

This is high level graphics programming and we don't have an example for it right now.

We will consider creating one.

/Alexandre

shark
sharkAuthor
Associate III
June 9, 2020

Yes, hope you can release an example soon.

I have a lot of needs of different size, that require a rectangle as a background image. And png file is too expensive in code space.

I checked existing widget and example, but failed.

Alexandre RENOUX
Visitor II
June 9, 2020

If it's a background image, why do you need round corners ? I'm still lost on what you are trying to do exactly as a project.

/Alexandre

Tuoman
Senior II
June 9, 2020

Should not be too difficult to program it yourself.

I'm glad that TouchGFX is not full of bloatware to keep it light.

If you do this feature, please add it to open repository:

https://github.com/touchgfx/touchgfx-open-repository/tree/master/widgets

Martin KJELDSEN
Principal III
June 10, 2020

You could simply use a box, and then have corners with alpha in some sizes to create the rounded corners. Depending on what you're doing you may experience performance issues since we cannot use ChromART to draw the kind of shape you're after.

/Martin