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 9073613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:27:25+00:00 2026-06-16T18:27:25+00:00

I noticed that some of the canvas2d methods seem to have a feature that

  • 0

I noticed that some of the canvas2d methods seem to have a feature that was surprising to me. In particular, the context.lineTo(x, y) and context.drawImg(imgObj, x, y) methods. I would have thought the x,y coordinates would be taken only in integers, but something special seems to happen if I give them as a float – the browser seems to magically adjust the color of the pixels on the edges of the graphical components to paint them “in between” the 2 discrete neighboring pixels coordinates.

For example, lets say my stroke color is black, and then I call context.lineTo(100.2, 0). I’ll get a nice black line the goes to x coordinate 100, but the pixel at coordinate 101 is also painted, but it’s painted a shade of grey that seems to correspond with the fractional part of the x coordinate(eg a darker grey for context.lineTo(100.4, 0))

I made a jsfiddle demo

where I animate both images and lines to demonstrate the effect visually. In both cases, the lower image and lower line were animated by passing floating point arguments to the canvas methods – and you can see how they’re very smooth due the browser doing its magic. The line effect is difficult to see at high monitor resolutions, but it’s there. The image is impressive because it doesn’t just blend the edges, it seems to be fully aware of transparency.

opera, firefox, and chrome all seem to do it.

My questions:
Is this documented in any browsers/spec?
Is there a term for this?

I want to call this some form of anti-aliasing or interpolation, but I don’t think either of these terms are correct for this. I want know what it’s called.

  • 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-16T18:27:26+00:00Added an answer on June 16, 2026 at 6:27 pm

    As most canvas systems, the one of HTML5 is based on float coordinates. And rounded coordinates are between screen pixels.

    This means that aliasing has to occur, in order to better fit pixels you put over more than one “real pixel”.

    This is a very important thing to know, as it lead to fuzzier and wider lines, depending on the position of the line. On the following picture, both lines have a lineWidth of 1 but the first one is drawed at y=1 while the second one is drawed at y=4.5:

    enter image description here

    See this post I wrote on this problem where I give 2 functions I made as an example of a way to deal with it (I use similar functions for rectangles too). More generally, you have to take into account the line width but the logic should be clear using the picture : to have sharp shapes, try to fill the real screen pixels.

    Drawing images at not integer coordinates smooths the image, which is rarely the desired effect, and also brings a performance penalty, as interpolation has to occur. You generally should draw your images, when they’re at screen scale, only on rounded coordinates, both for performances and for fidelity to original.

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

Sidebar

Related Questions

You probably noticed that some web sites have a feedback feature created with http://uservoice.com
I have noticed that some tutorials use self.up and self.down for migration methods. I
I noticed that some enumerations have None as a enumeration member. For example what
I noticed that some stylesheets have something like this: body { font-size: 62.5%/1.2em; }
I have 100 web servers and noticed that some of them have request filtering
I noticed that some arrays don't have a comma after the last item. I
I have noticed that some WPF controls have some decent effects available to them
I've noticed that some programs have their own tab-completion. For example, git: git checkout
I have noticed that some applications (BeejiveIM) that you can put the red badge
I've noticed that some sites (including the old http://careers.stackoverflow.com 1.0) have query strings that

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.