Javascript load a random image -


i want create javascript function load random image when function da_image called. want image load onto canvas have set up. there clear error in code? nothing displaying.

var images = [                     "http://circlesfordialogue.com/wp-content/uploads/2014/12/laura-let%c2%b4s-circle-up-2014-12-08.jpg",                     "http://mathworld.wolfram.com/images/eps-gif/concentriccircles_1000.gif",                      "http://www.charlespetzold.com/blog/2012/12/beziercirclefigure3.png"              ];             function da_image(){                 var file = images[0];                  var reader = new filereader();                 reader.onload = function(){                         var img = new image();                         img.src = reader.result;                         img.onerror = function(){                             reset_canvas();                             o.font = '30px sans-serif'                             o.filltext('error: invalid image ' + file.name, 50, 100);                         }                         img.onload = function(){                             document.getelementbyid("text").innerhtml = 'recognizing text... may take while...'                             reset_canvas();                             var rat = math.min(c.width / img.width, c.height / img.height);                             o.drawimage(img, 0, 0, img.width * rat, img.height * rat)                             var tmp = document.createelement('canvas')                             tmp.width = img.width;                             tmp.height = img.height;                             var ctx = tmp.getcontext('2d')                             ctx.drawimage(img, 0, 0)                             var image_data = ctx.getimagedata(0, 0, tmp.width, tmp.height);                             runocr(image_data, true)                         }                      } 

the onload handler triggered when image loaded. when image loaded when set onload handler, doesn't triggered.

so set .src attribute after set .onload function.


Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -