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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:28:05+00:00 2026-06-16T00:28:05+00:00

I am having a small bug which seems to indicate that the onload function

  • 0

I am having a small bug which seems to indicate that the onload function is being called prior to the image being fully loaded, when you pass in image data as its source.

This is the HTML

<html>
<head>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>
</head>
<body>
    <canvas id='finalImage'></canvas>
</body>
</html>​

This is the javascript:

var canvas = document.createElement('canvas');
var context = canvas.getContext('2d');

var image = new Image();
image.onload = function() {
    // I've also put a console.log here at one point, and it does get called.
    context.drawImage(image, 0, 0, canvas.width, canvas.height);
};
image.src = "data:image/jpeg;base64,/9j/4QNMR..."; // cut for sanity.

var outputCanvas = $("#finalImage")[0];
var outputContext = outputCanvas.getContext('2d');

// If I uncomment this line, the image is drawn.
//context.drawImage(image, 0, 0, canvas.width, canvas.height);

// If I change canvas to image, its also drawn, which means it is being loaded.
// But it seems to indicate to me that onload gets called too early.
outputContext.drawImage(canvas, 0, 0);​

Here is the link to the JSFiddle..

Let me know if you find what is wrong with it, been messing with it for quite a bit now.

Thanks!

  • 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-16T00:28:06+00:00Added an answer on June 16, 2026 at 12:28 am

    outputContext.drawImage(canvas, 0, 0);​ calls before context.drawImage(image, 0, 0, canvas.width, canvas.height); to guarantee that outputContext is drawn to after canvas is to put it in the onload function

    var canvas = document.createElement('canvas');
    var context = canvas.getContext('2d');
    
    var image = new Image();
    var outputCanvas = $("#finalImage")[0];
    var outputContext = outputCanvas.getContext('2d');
    image.onload = function() {
        // I've also put a console.log here at one point, and it does get called.
        context.drawImage(image, 0, 0, canvas.width, canvas.height);
        outputContext.drawImage(canvas, 0, 0);​
    };
    image.src = "data:image/jpeg;base64,/9j/4QNMR..."; // cut for sanity.
    

    http://jsfiddle.net/mowglisanu/ruKht/14/

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

Sidebar

Related Questions

I'm having a small web app, which plays really short sound bits on the
Having a small problem finding a function or method to do what I'm looking
I'm having a small problem, that I just cannot figure out. I have a
I am having a small issue with the mysqli_stmt prepare function. Here is my
I am having a small problem- How would I write a function in mysql
i am having a small problem here. The table which dbml (LinqToSql designer) is
OSGi seems to have an excellent benefit of having small deployable artifacts by not
I'm having a small problem in Java. I have an interface called Modifiable. Objects
I'm having a small issue, I have some code that calculates a mean value
Im having a bug on some devices that sometimes give an ANR when starting

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.