• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Turn off Anti-aliasing for HTML5 Canvas Projects?

Participant ,
Oct 02, 2024 Oct 02, 2024

Copy link to clipboard

Copied

DigitalDesignDude_0-1727900779054.png

 

I would like to use pixel art in my HTML5 Canvas projects, but I'm unsure how I can disable the antialiasing or blurring that occurs when the bitmaps or the canvas itself is scaled up.

 

I know for ActionScript projects, I can turn off "Allow smoothing" from the Bitmap properties to prevent this. But that doesn't seem to work in HTML5 canvas projects, from what I've tested.

I've also tried adding the following CSS and JavaScript code to Animate's generated HTML file, but that did not seem to make any noticeable difference either. 

 

<style>
    /*Set canvas to use nearest neighbor scaling algorithm*/
    canvas {
        image-rendering: pixelated;
    }
</style>


<script>
    //Get a reference to the canvas
    canvas = document.getElementById("canvas");

    // Get the canvas context
    var ctx = canvas.getContext("2d");

    // Attempt to disable smoothing 
    ctx.imageSmoothingEnabled = false;
    ctx.webkitImageSmoothingEnabled = false;
    ctx.mozImageSmoothingEnabled = false;
</script>

 

 
Thank you for any help you can provide in fixing this issue.

TOPICS
Code , Missing feature

Views

269

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Oct 02, 2024 Oct 02, 2024

Hi.

 

You should only need to turn off image smoothing on the canvas' 2D context by running the code below in the main timeline:

canvas.getContext("2d").imageSmoothingEnabled = false;

 

Regards,

JC

Votes

Translate

Translate
Community Expert ,
Oct 02, 2024 Oct 02, 2024

Copy link to clipboard

Copied

Hi.

 

You should only need to turn off image smoothing on the canvas' 2D context by running the code below in the main timeline:

canvas.getContext("2d").imageSmoothingEnabled = false;

 

Regards,

JC

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 02, 2024 Oct 02, 2024

Copy link to clipboard

Copied

Fantastic! That worked very well. Thank you, JC. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 02, 2024 Oct 02, 2024

Copy link to clipboard

Copied

LATEST

Awesome! You're welcome!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines