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

  • Home
  • SEARCH
  • 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 9208491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:37:45+00:00 2026-06-18T00:37:45+00:00

I have a problem while i work with canvas. See below code. HTML <canvas

  • 0

I have a problem while i work with canvas. See below code.

HTML

<canvas id="canvas" width="400" height="400"></canvas>    
<input id="but" type="button" value="clear canvas" onclick="ClearCanvas()">

JS

can = document.getElementById('canvas');
ctx = can.getContext("2d");

ctx.fillStyle = 'rgb(205,190,245)';
ctx.fillRect(0, 0, can.width, can.height);

ctx.scale(0.4, 0.4);
ctx.fillStyle = 'rgb(105,180,235)';
ctx.fillRect(0, 0, can.width, can.height);

$("#but").click(function()
{
    var ctx = document.getElementById('canvas').getContext("2d");

    ctx.scale(1, 1);
    ctx.clearRect(0, 0, can.width, can.height);
});

While i click on “clear canvas” button, it is not clearing entire canvas. It is just clearing the portion that was scaled. How to clear whole canvas after did scaling?

You can catch this live in this FIDDLE

Note: No problem in FF.

  • 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-18T00:37:46+00:00Added an answer on June 18, 2026 at 12:37 am

    Your line:

    ctx.scale(1, 1);
    

    Should read:

    ctx.scale(2.5, 2.5);
    

    Initially you reduced the scale from 1 to 0.4 which is 2.5 times smaller than the original scale. (1 / 0.4 = 2.5)

    Setting a scale to 1 will scale by 100% i.e no change.

    Other options are:

    • Replace ctx.scale(1, 1); with ctx.setTransform(1, 0, 0, 1, 0, 0);
    • Use Save() and Restore() link
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I never seemed to have this problem while doing Rails work in Linux, but
I have a problem while trying to use createLinearGradient //linear gradient canvas.beginPath(); canvas.arc(350,400,100,0,2*Math.PI,false); canvas.strokeStyle
I have problem while loading data into html select when users press or click
I have a problem while pasting my contents (or text) generated by Java code
I have this peculiar problem while wanting to print a html-report. The file itself
I have problem while using jquery maskedinput with asp.net textbox. I have a check
I have a problem while converting a string whose value is dd.mm.yyyy to DateTime
I have a problem while executing a SSIS script component. To be honest I
I have a problem while scrolling images on tableview. I am getting a Signal
i have a problem while loading a UITableView on UITabBarController, i got this error

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.