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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:45:31+00:00 2026-06-16T19:45:31+00:00

In my javascript i draw onto a canvas, after that i whant the canvas

  • 0

In my javascript i draw onto a canvas, after that i whant the canvas to be converted to a png and shown in a div with the folowing code:

var dataURL = document.getElementById('myCanvas').toDataURL("image/png");
var imgObj = new Image();
imgObj.src = dataURL;
imgObj.onload = function() {document.getElementById('myImg').appendChild(imgObj); };

When i call this directly after drawing the canvas i get a completly blank image in “myImg” but if i call exactly the same code with the click on a link it gets drawn properly:

<a id="viewImgLnk" href="javascript:void()" onclick=" return convertCanvasToImage();">View Image</a>

<script>
    function convertCanvasToImage(){
        var dataURL = document.getElementById('myCanvas').toDataURL("image/png");
        var imgObj = new Image();
        imgObj.src = dataURL;
        imgObj.onload = function() {document.getElementById('myImg').appendChild(imgObj); };
    }
</script>

How can i get the image loaded directly without the link?

  • 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-16T19:45:32+00:00Added an answer on June 16, 2026 at 7:45 pm

    I got the code working with the help of allergic!

    setTimeout(function() {
        var dataURL = document.getElementById('myCanvas').toDataURL("image/png");
        var imgObj = new Image();
        imgObj.src = dataURL;
        imgObj.onload = function() {document.getElementById('myImg').appendChild(imgObj); };
    }, 300);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

so having a canvas and canvasContext I want to draw an image onto that
I am using javascript to draw to a canvas element inside a div, contained
I have a function that draw something on a canvas after triggering the if
I'm looking for Javascript code for letting the user draw a line (on an
i have a JavaScript project (using jquery), inside it i draw a canvas by
javascript code: function getCheckbox(name,id){ var check = 0; var deger = option-checkbox-+id; var dom
Javascript I have code that will hide various sections in a MS CRM form
I'm trying to render a PNG image that is stored in a javascript Uint8Array
I am trying to use the technique shown here: http://joelb.me/blog/2011/code-snippet-accessing-clipboard-images-with-javascript/ to capture an image
In javascript, I am trying to draw a line that is at an angle

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.