Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7765735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:14:18+00:00 2026-06-01T15:14:18+00:00

Sorry if this belongs on a maths forum. I have an image rounded corners

  • 0

Sorry if this belongs on a maths forum. I have an image rounded corners within HTML5s canvas element, I want to make the rounded corners transparent. I have the following code:

    var cornersImgData = tempContext.getImageData(0, 0, img.width, img.height);
    var topLeft = getPixel(cornersImgData, 0, 0);
    var topRight = getPixel(cornersImgData, cornersImgData.width - 1, 0);
    var bottomLeft = getPixel(cornersImgData, 0, cornersImgData.height - 1);
    // Check that the rounded corners have actually been applied (e.g. make sure the user hasn't just clicked the button and then undo)
    var bottomRight = getPixel(cornersImgData, cornersImgData.width - 1, cornersImgData.height - 1);
    if (('rgb(' + topLeft[0] + ', ' + topLeft[1] + ', ' + topLeft[2] + ')' == _roundedCornersColour) ||
        ('rgb(' + topRight[0] + ', ' + topRight[1] + ', ' + topRight[2] + ')' == _roundedCornersColour) ||
        ('rgb(' + bottomLeft[0] + ', ' + bottomLeft[1] + ', ' + bottomLeft[2] + ')' == _roundedCornersColour) ||
        ('rgb(' + bottomRight[0] + ', ' + bottomRight[1] + ', ' + bottomRight[2] + ')' == _roundedCornersColour))
    {
        for (var x = 0; x < cornersImgData.width; x++)
        {
            for (var y = 0; y < cornersImgData.height; y++)
            {
                var colour = getPixel(cornersImgData, x, y);
                if ('rgb(' + colour[0] + ', ' + colour[1] + ', ' + colour[2] + ')' == _roundedCornersColour)
                {
                    setPixel(cornersImgData, x, y, colour[0], colour[1], colour[2], 0);
                }
            }
        }
    }

This works but because I am replacing every instance of _roundedCornersColour I sometimes end up replacing a few pixels within the image itself. My high school maths is a little rusty and I can’t figure out the best way to determine if x and y fall outside of where the corner should be. Can anyone help please?

Joe

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T15:14:19+00:00Added an answer on June 1, 2026 at 3:14 pm

    If the radius is r, then the center of the circle of which the top-left rounded corner are is an arc is at (xc1, yc1) = (r, r), as far as I can tell from your code. You can similarly work out the coordinates of the other three circle centers (xc2, yc2), (xc3, yc3) and (xc4, yc4).

    Then near the first corner, you can test if (x-xc1)*(x-xc1) + (y-yc1)*(y-yc1) > r*r and x < xc1 and y < yc1. This is satisfied by points that are outside the circle and in the relevant corner. In the other corners you’ll need to change the circle center in the first test to the relevant circle center, and change the other two inequalities appropriately to select the correct quadrant of the circle.

    That’s the basic math. There are many optimizations you could apply for speed, such as the fact that the four corners are all symmetric (each corner has reflective symmetry about a diagonal line and all the corners are rotated copies of each other), and that once you’ve found one point outside the circle you can immediately identify a lot of other points that are also outside it without testing them directly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry if this question belongs somewhere else. I am going through the source for
Sorry if this belongs on serverfault I'm wondering what the proper way is to
I have a form, that looks like this (sorry for Haml and the german
Sorry this is not a very well defined question, I am thinking about an
Sorry this is a basic question, but all my research just barely missed answering
Sorry this is probably super basic. But in all my javabean examples, I've not
sorry this is such a simple question but I can't figure it out. How
I'd like to remove the popup message 'Sorry this video cannot be played' from
Sorry for this simple question, but I can't solve it... There is an example:
Sorry if this question seems stupid, but it's stumped me for a couple days,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.