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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:20:32+00:00 2026-06-03T19:20:32+00:00

I am trying to make a pixel art themed game in HTML5 canvas, and

  • 0

I am trying to make a pixel art themed game in HTML5 canvas, and as part of that I take 10×20 or so sized images and draw them onto the canvas with the following code:

ctx.drawImage(image, 20, 20, 100, 200);

However the canvas uses bicubic image scaling and hence the pixel art images look terrible at 2× and up. Is there a way to force canvas to use nearest neighbor scaling or possibly use a custom method to scale images? If not, does that mean the images have to be scaled beforehand in something like Paint.net?

  • 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-03T19:20:40+00:00Added an answer on June 3, 2026 at 7:20 pm

    Choose any one of the following:


    Via JavaScript:

    ctx.imageSmoothingEnabled = false;
    

    Source: http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#image-smoothing

    On Gecko, you’ll need

    ctx.mozImageSmoothingEnabled = false;
    

    Source: https://developer.mozilla.org/en/DOM/CanvasRenderingContext2D#Gecko-specific_attributes

    On Webkit, you’ll need

    ctx.webkitImageSmoothingEnabled = false;
    

    Source: https://bugs.webkit.org/show_bug.cgi?id=82804

    I couldn’t find information on support of this property on other browsers, so they probably don’t support it.


    Via CSS:

    Another option is to use a set of CSS rules on the canvas. For example:

    <canvas id="c" width="16" height="16"></canvas>
    <script>
      var c = document.getElementById("c"),
          cx = c.getContext("2d"),
          im = new Image();
      im.src = "http://stackoverflow.com/favicon.ico"; // 16x16
      cx.drawImage(im, 0, 0);
    </script>
    <style>
      canvas {
        width: 32px;
        height: 32px;
        image-rendering: optimizeSpeed;
        image-rendering: crisp-edges;
        image-rendering: -moz-crisp-edges;
        image-rendering: -o-crisp-edges;
        image-rendering: -webkit-optimize-contrast;
        -ms-interpolation-mode: nearest-neighbor;
      }
    </style>
    

    Source: https://developer.mozilla.org/en/CSS/image-rendering
    Source: https://bugs.webkit.org/show_bug.cgi?id=56627


    Via pixel routines:

    Yet another option is to do it yourself using the canvas pixel manipulation routines: http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#pixel-manipulation. That’s a lot more work, though.

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

Sidebar

Related Questions

I am trying to make a something that will draw lines on a pixel
I have been trying to make a script that compares two images in HTML5
I am trying to figure out how to make my game draw a certain
Using XNA, I'm trying to make an adventure game engine that lets you make
I'm trying to make an app that will take two pictures you specify via
I'm trying make an entity with doctrine that has three associations with other entities
Trying to make this jQuery filter that uses .find case-insensitive. For example, when the
Trying to make an xna game, where the user needs to tap to stop
Ok, I'm trying to make a program that finds the position of a colored
I'm trying to make a single-file HTML test case for something + part of

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.