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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:33:51+00:00 2026-05-31T01:33:51+00:00

EDIT : I just found something that works on every page load except the

  • 0

EDIT : I just found something that works on every page load except the first (hard) load. It’s a ‘weird tip to get it to work’ because it does not use onload. E.g.

This works on loads 2…n:

case String:
        var img = new Image();
        img.onload = function() {
            //context.drawImage(img,0,0);
        };
        img.src = detail;
        context.drawImage(img,0,0);

This does not work on any load 1…n:

case String:
        var img = new Image();
        img.onload = function() {
            context.drawImage(img,0,0);
        };
        img.src = detail;
        //context.drawImage(img,0,0);

I am not very happy that I miss the most important load (the first one), but at least there is some progress.

Can someone guide me to explain what is going on here? I’m really baffled. I want image to load and draw to canvas every time. Is this an unrealistic expectation?

I’m using FF 7.0.1 on Ubuntu, my user agent is : Mozilla/5.0 (X11; Linux i686; rv:7.0.1) Gecko/20100101 Firefox/7.0.1

EDIT : Still fail after all approaches tried in comments. I will keep thinking about it. I think it has something to do with the canvas no longer being accessible (even though the variable resolves correctly and no error is thrown in JS Debugger under FF).

I am writing a js framework for rendering to canvas to provide an easy API to write GUI with less code and prettier code than using Canvas API. It’s just a wrapper around canvas. But I am not a js expert even though I love js, now anyway.

The following code in the closure can execute and access the scope of the img variable, can raise an alert form that scope on image load, can change the img css style properties, but will not execute a drawImage on the canvas context in context variable.

Before the closure context.fillRect will work fine, but inside the closure it does not. I think there is something fundamental I have not learned yet, since I have coded similar onload with closure looking code before and everything just worked. Hopefully today is the day I learn something new.

RenderProvider.prototype.drawImage = function(srcElement,context,state,detail) {
    if(detail == undefined || detail == null) {
        alert("Image is not present. Ignoring.");
        return;
    }   
    switch(detail.constructor) { 
        case String:
                alert("Image is from String");
                var img = new Image();
                img.src = detail;//'t.jpg';//'Star-Field.gif';//http://www.google.com/favicon.ico';
                img.onload = function (e) { 
                    alert('Drawing ' + img + ' to ' + context);
                    alert('Context dim ' + context.canvas.width + ',' + context.canvas.height );
                    context.drawImage(img,20,20);
                    return true;
                };          
                img.src = detail;//'t.jpg';//'Star-Field.gif';//'http://www.google.com/favicon.ico';
                break;
  • 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-31T01:33:52+00:00Added an answer on May 31, 2026 at 1:33 am

    You need to wait for the window.onload event as well as the image onload event, as Phil H is suggesting. Are you doing that? I tested your first sample up there but waited for window.onload and it works on the first load. The second one does not work. I am not sure why.

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

Sidebar

Related Questions

I wanted to edit just the first line of a 4 MB file. When
EDIT I've just started skimming Codd's famous 1970 paper that started it all, that
** EDIT ** Nevermind, just needed to take out the parens... I get this
I have just successfully installed CakePHP and I see that I can edit the
I'm just starting with jQuery, and having trouble doing something embarrassingly simple: using .load()
I have a page that uses jQuery's $.post() method to get some html and
EDIT: Just to make things clear, this problem was caused by a typo in
(Edit: randrange is just random.randrange, I didn't write my own RNG) I'm trying to
Edit: I fixed the problem by just starting from scratch. Sorry to waste y'alls
EDIT AGAIN ... I'm just a dummy and figured it out! EDIT: So, it

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.