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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:36:25+00:00 2026-05-19T16:36:25+00:00

I am using HTML5 canvas as follows: Display an image that fills the canvas

  • 0

I am using HTML5 canvas as follows:

  1. Display an image that fills the canvas area.
  2. Display a black text label over the image.
  3. On click of the text label highlight it by drawing a filled red rect + white text.

I have that part all working fine. Now what I want to do is remove the red rect and restore the image background that was originally behind it. I’m new to canvas and have read a fair amount, however I can’t see how to do this. That said I am sure it must be quite simple.

  • 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-19T16:36:25+00:00Added an answer on May 19, 2026 at 4:36 pm

    I think there are some ways…

    Redraw all stuff after the click release

    This is simple but not really efficient.

    Redraw only the altered part

    drawImage with 9 arguments to redraw only the altered background image part, then redraw the black text over.

    Save image data before click and then restore it

    This uses getImageData and putImageData of the 2D context. (Not sure that it’s widely implemented though.)

    Here the specification:

    ImageData getImageData(in double sx, in double sy, in double sw, in double sh);
    void putImageData(in ImageData imagedata, in double dx, in double dy, in optional double dirtyX, in double dirtyY, in double dirtyWidth, in double dirtyHeight);
    

    So for instance if the altered part is in the rect from (20,30) to (180,70) pixels, simply do:

    var ctx = canvas.getContext("2d");
    var saved_rect = ctx.getImageData(20, 30, 160, 40);
    // highlight the image part ...
    
    // restore the altered part
    ctx.putImageData(saved_rect, 20, 30);
    

    Use two superposed canvas

    The second canvas, positioned over the first, will hold the red rect and the white text, and will be cleared when you want to “restore” the original image.

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

Sidebar

Related Questions

How can i adjust the contrast of an image using HTML5 Canvas pixel manipulation
I'm drawing simple text in HTML5 canvas using this: context.fillStyle = #FF0000 context.font =
I'm trying to draw an animation over google maps, hopefully using html5's canvas element.
I am creating an image viewer application using HTML5 canvas. I have used two
Using HTML5 Canvas and Javascript I need to display different values (represented by a
I've been trying to develop a text-editor (as a personal project) using HTML5 canvas,
I am wanting to create a gallery using HTML5 Canvas Black for hover effects
I am looking at using HTML5 Canvas element for my upcoming project. I want
I am making a game engine using HTML5 canvas, and I have decided to
I am creating a web application using HTML5 canvas to draw images ( like

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.