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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:30:18+00:00 2026-06-03T10:30:18+00:00

Recently I started working on HTML5 Canvas, I’m new to it. I’ve a problem

  • 0

Recently I started working on HTML5 Canvas, I’m new to it.
I’ve a problem as follows:

I’m loading a Canvas with Body Chart Image (Predefined Image) and on that User will Draw some lines, shapes, etc.

After that I’ll generate an image object as follows

var canvas = document.getElementById("MyCanvas");
var dataURL = canvas.toDataURL();
var image = new Image();
image.src = dataURL;

But, Here it generates only those elements which are drawn by users (lines, shapes) as PNG Image. It won’t take that Predefined canvas background Image.

I need to generate a PNG image which should include both the Canvas background Image as well as User entered drawing elements.

How to do this?

  • 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-03T10:30:19+00:00Added an answer on June 3, 2026 at 10:30 am

    Try to actually draw you image onto your canvas, utilizing these functions:

      var canvas = document.getElementById("MyCanvas");
      var img = new Image();
      img.src = 'pathToYourImageHere';
      canvas.drawImage(img,0,0); /* 0,0 is x and y from the top left */
    

    When you now try to save it, it should also save your background image.

    EDIT:
    In response to your comment:

    You can circument your layering problem by using two different canvases. One for the image, and one for your drawing. Then layer them on top of each other using absolute positioning.
    You can read more here: Save many canvas element as image

    EDIT2:
    But actually you shouldn’t have a layering problem, since the following code will first draw the image and then draw the arc, and the layering will be fine:

    var canvas = document.getElementById("myCanvas");
    var context = canvas.getContext("2d");
    var imageObj = new Image();
    imageObj.src = "somePathToAnImage";
    context.drawImage(imageObj, 50, 50);   
    
    var x = canvas.width / 2;
    var y = canvas.height / 2;
    var radius = 75;
    var startAngle = 1.1 * Math.PI;
    var endAngle = 1.9 * Math.PI;
    var counterClockwise = false;
    
    context.beginPath();
    context.arc(x, y, radius, startAngle, endAngle, counterClockwise);
    context.lineWidth = 15;
    // line color
    context.strokeStyle = "red";
    context.stroke();  
    

    Even though the layering is fine, you will be better of by using two canvases, in case you would like to only save the drawing, without the background. You can always save both into a new canvas and save that, when you only use one canvas you’ll have a hard time separating the drawing from the background.

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

Sidebar

Related Questions

I have recently started working on my master thesis in C that I haven't
I have a project that I have recently started working on seriously but had
I recently started working in VS2010 and noticed right away that the font I
I have recently started working on a very large C++ project that, after completing
Recently I started working with MVC, before that I used classic ASP.NET. After using
I recently started working with the AudioToolbox framework and noticed that there is a
I have recently started working on a legacy application that has most of its
I recently started working with MVC or MVC2 to be more exact. I found
I've recently started working with an application written using Adobe Flex 3. We're using
We recently started working with XML files, after many years of experience with the

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.