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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:53:36+00:00 2026-05-11T06:53:36+00:00

I seem to have hit an error message that I’m having a hard time

  • 0

I seem to have hit an error message that I’m having a hard time debugging. What I’m trying to do is dynamically create an image such as this one ( http://www.webreference.com/programming/javascript/mk/column3/creating/cp_mini_gradient_details.png ) with canvas.

The error message I’m getting is:

[Exception... 'An invalid or illegal string was specified' code: '12' nsresult: '0x8053000c (NS_ERROR_DOM_SYNTAX_ERR)'] 

I’ve googled and there seems to be a number of causes for this error message, but I can’t seem to find any relating to canvas specifically.

Here is my code:

var newCanvas = document.createElement('canvas'); newCanvas.height='30'; newCanvas.width='113'; document.body.appendChild(newCanvas);  var context = newCanvas.getContext('2d');  context.fillStyle = '#FFFFFF';   context.fillRect(0, 0, 113, 15); context.fillStyle = '#000000';   context.fillRect(0, 15, 113, 30);  var numCanH = Number(newCanvas.height); var numCanW = Number(newCanvas.width); var imgd; if (context.createImageData) {     console.log('context.createImageData');     imgd = context.createImageData(numCanW, numCanH); }  else if (context.getImageData) {     console.log('context.getImageData');     imgd = context.getImageData(0, 0, numCanW, numCanH); }  else {     console.log('else');     imgd = {'width' : numCanW, 'height' : numCanH, 'data' : new Array(numCanW*numCanH*4)}; }   var pix = imgd.data; var ndv = numCanW/6;  for (var i = 0; i <= numCanH; i++) {      var a=1-Math.abs(2*i-numCanH)/numCanH;      for (var j = 0; j < numCanW; j+=4) {          var bitUp = Math.ceil((255/130)*j);         var bitDown = 255-bitUp;          if(j<(ndv)){    //Red to Yellow - (rgb) 255,0,0 to 255,255,0             pix[j] = 255; // red channel             pix[j+1] = bitUp; // green channel             pix[j+2] = 0; // blue channel          }             else if(j>(ndv) && j<(ndv)*2){  //Yellow to Green - (rgb) 255,255,0 to 0,255,0             pix[j] = 255; // red channel             pix[j+1] = bitDown; // green channel             pix[j+2] = 0; // blue channel          }           else if(j>(ndv)*2 && j<(ndv)*3){    //Green to Cyan - (rgb) 0,255,0 to 0,255,255             pix[j] = 0; // red channel             pix[j+1] = 255; // green channel             pix[j+2] = bitUp; // blue channel          }           else if(j>(ndv)*3 && j<(ndv)*4){    //Cyan to Blue - (rgb) 0,255,255 to 0,0,255             pix[j] = 0; // red channel             pix[j+1] = bitDown; // green channel             pix[j+2] = 255; // blue channel          }           else if(j>(ndv)*4 && j<(ndv)*5){    //Blue to Magenta - (rgb) 0,0,255 to 255,0,255             pix[j] = bitUp; // red channel             pix[j+1] = 0; // green channel             pix[j+2] = 255; // blue channel          }           else if(j>(ndv)*5 && j<(ndv)*6){    //Magenta to Red - (rgb) 255,0,255 to 255,0,0             pix[j] = 255; // red channel             pix[j+1] = 0; // green channel             pix[j+2] = bitDown; // blue channel          }                       pix[j+3] = a; // alpha channel+          console.log('bitUp  '+bitUp);         console.log(typeof bitUp);         console.log('bitDown  '+bitDown);         console.log(typeof bitDown);         console.log('a  '+j);         console.log(typeof a);         console.log('j  '+j);         console.log(typeof j);         console.log('i  '+i);         console.log(typeof i);         console.log(imgd);         console.log('before context.putImageData');         context.putImageData(imgd, j,i);         console.log('after context.putImageData');           } } 

The weird thing is, the error only occurs during the second iteration of the loop.

  • 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. 2026-05-11T06:53:36+00:00Added an answer on May 11, 2026 at 6:53 am

    Your putImageData call is trying to draw the entirety of imgd, which you created to be the canvas’s width and height, into the canvas with top left corner at (j,i). This fails after the first iteration of the lop because the bottom / right of imgd go off the bottom / right of the canvas.

    Take the putImageData call outside the outer loop and make it always draw at (0,0). Also, when working out the array index of the pixel you are setting, don’t forget to add in i*numCanW*4; and note that your inner loop needs to go from 0 to iCanW*4 not 0 to iCanW as you are interating over colour components, not pixels.

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

Sidebar

Ask A Question

Stats

  • Questions 170k
  • Answers 170k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Update: This was a bug in older versions of Xcode.… May 12, 2026 at 2:10 pm
  • Editorial Team
    Editorial Team added an answer I'd use C++/CLI for gluing together .net tests and native… May 12, 2026 at 2:10 pm
  • Editorial Team
    Editorial Team added an answer CAPICOM uses standard encryption algorithms such as 3DES. If you… May 12, 2026 at 2:10 pm

Related Questions

I seem to have hit an error message that I'm having a hard time
Short version: Is it easy/feasible/possible to program modal window in Flash (AS3)? Is there
I'm following along with this useful looking answer to my question . It seems
I cannot seem to get a nested form to generate in a rails view
I'm looking for a way in .NET (2.0, C# in particular) for source code

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.