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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:11:59+00:00 2026-05-26T00:11:59+00:00

NOTE : This has to do with how existing canvas elements are rendered when

  • 0

NOTE: This has to do with how existing canvas elements are rendered when scaled up, not to do with how lines or graphics are rendered onto a canvas surface. In other words, this has everything to do with interpolation of scaled elements, and nothing to do with antialiasing of graphics being drawn on a canvas. I’m not concerned with how the browser draws lines; I care about how the browser renders the canvas element itself when it is scaled up.


Is there a canvas property or browser setting I can change programmatically to disable interpolation when scaling <canvas> elements? A cross-browser solution is ideal but not essential; Webkit-based browsers are my main target. Performance is very important.

This question is most similar but does not illustrate the problem sufficiently. For what it’s worth, I have tried image-rendering: -webkit-optimize-contrast to no avail.

The application will be a “retro” 8-bit styled game written in HTML5+JS to make it clear what I need.


To illustrate, here is an example. (live version)

Suppose I have a 21×21 canvas…

<canvas id='b' width='21' height='21'></canvas>

…which has css that makes the element 5 times larger (105×105):

canvas { border: 5px solid #ddd; }
canvas#b { width: 105px; height: 105px; } /* 5 * 21 = 105 */

I draw a simple ‘X’ on the canvas like so:

$('canvas').each(function () {
    var ctx = this.getContext("2d");
    ctx.moveTo(0,0);
    ctx.lineTo(21,21);
    ctx.moveTo(0,21);
    ctx.lineTo(21,0);
    ctx.stroke();
});

The image on the left is what Chromium (14.0) renders. The image on the right is what I want (hand-drawn for illustrative purposes).

Chrome interpolates scaled canvas elements A non-interpolated version

  • 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-05-26T00:12:00+00:00Added an answer on May 26, 2026 at 12:12 am

    Last Updated: 2014-09-12

    Is there a canvas property or browser setting I can change programmatically to disable interpolation when scaling elements?

    The answer is maybe some day. For now, you’ll have to resort to hack-arounds to get what you want.


    image-rendering

    The working draft of CSS3 outlines a new property, image-rendering that should do what I want:

    The image-rendering property provides a hint to the user-agent about what aspects of an image are most important to preserve when the image is scaled, to aid the user-agent in the choice of an appropriate scaling algorithm.

    The specification outlines three accepted values: auto, crisp-edges, and pixelated.

    pixelated:

    When scaling the image up, the “nearest neighbor” or similar algorithm must be used, so that the image appears to be simply composed of very large pixels. When scaling down, this is the same as auto.

    Standard? Cross-browser?

    Since this is merely a working draft, there’s no guarantee that this will become standard. Browser support is currently spotty, at best.

    The Mozilla Developer Network has a pretty thorough page dedicated to the current state of the art which I highly recommend reading.

    The Webkit developers initially chose to tentatively implement this as -webkit-optimize-contrast, but Chromium/Chrome don’t seem to be using a version of Webkit that implements this.

    Update: 2014-09-12

    Chrome 38 now supports image-rendering: pixelated!

    Firefox has a bug report open to get image-rendering: pixelated implemented, but -moz-crisp-edges works for now.

    Solution?

    The most cross-platform, CSS-only solution so far is thus:

    canvas {
      image-rendering: optimizeSpeed;             /* Older versions of FF          */
      image-rendering: -moz-crisp-edges;          /* FF 6.0+                       */
      image-rendering: -webkit-optimize-contrast; /* Safari                        */
      image-rendering: -o-crisp-edges;            /* OS X & Windows Opera (12.02+) */
      image-rendering: pixelated;                 /* Awesome future-browsers       */
      -ms-interpolation-mode: nearest-neighbor;   /* IE                            */
    }
    

    Sadly this wont work on all major HTML5 platforms yet (Chrome, in particular).

    Of course, one could manually scale up images using nearest-neighbor interpolation onto high-resolution canvas surfaces in javascript, or even pre-scale images server-side, but in my case this will be forbiddingly costly so it is not a viable option.

    ImpactJS uses a texture pre-scaling technique to get around all this FUD. Impact’s developer, Dominic Szablewski, wrote a very in-depth article about this (he even ended up citing this question in his research).

    See Simon’s answer for a canvas-based solution that relies on the imageSmoothingEnabled property (not available in older browsers, but simpler than pre-scaling and pretty widely-supported).

    Live Demo

    If you’d like to test the CSS properties discussed in the MDN article on canvas elements, I’ve made this fiddle which should display something like this, blurry or not, depending on your browser:
    a 4:1 (64x64 to 256x256) image of an isometric pixel-art style TV

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

Sidebar

Related Questions

Note: This question has broadened in scope from previous revisions. I have tried to
Has anyone seen this type of IE display problem? Example http://xs133.xs.to/xs133/08465/ie_problem910.jpg.xs.jpg Note that it
(Note: This is for MySQL's SQL, not SQL Server.) I have a database column
Note This is not a REBOL-specific question. You can answer it in any language.
(NOTE: This question is not about escaping queries, it's about escaping results) I'm using
NOTE: This question has been updated to provide more detail and insight than the
I am updating an existing ASP .NET site. This site has a custom grid
Note: This was posted when I was starting out C#. With 2014 knowledge, I
Note: this is a different problem to https - it's related to privacy security
Note: This is the opposite direction to most similar questions! I have an iPhone

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.