Load and draw image with canvas

function loadImage(srcPath, _x, _y) { var canvas = document.getElementById('canvas'); if (!canvas || !canvas.getContext) { // canvas is not supported. return; } var context = canvas.getContext('2d'); // create image object var img = new Image(); //img.src = "http://codepad.co/images/body/logo.png?" + new Date().getTime(); img.src = srcPath; // wait until source is loaded img.onload = function() { ctx.drawImage(img, _x, _y); } }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.