How to position Path2D SVG element in canvas?

Use the transform to move the path Using CanvasRenderingContext2D.translate const canvas = document.getElementById(‘canvas’); const ctx = canvas.getContext(‘2d’); let p = new Path2D(‘M10 10 h 80 v 80 h -80 Z’); ctx.translate(100, 100); ctx.fill(p); or using CanvasRenderingContext2D.setTransform let p = new Path2D(‘M10 10 h 80 v 80 h -80 Z’); ctx.setTransform(1, 0, 0, 1, 100, 100); … Read more

HTML5 drag and drop images from a toolbar to a canvas

Demo: http://jsfiddle.net/m1erickson/2Us2S/ Use jquery-ui to create draggable elements. $(“#myToolbarImageElement”).draggable(); Load these elements with data payloads which are key-value pairs. In your case this might be an image object that you want drawn on the canvas. $(“#myToolbarImageElement”).data(“image”,myImageObject); Set your canvas as a drop zone: $(“#myCanvas”).droppable({drop:myDropHandler}); When you drop the elements on canvas you can read the … Read more

Converting bytes to an image for drawing on a HTML5 canvas

I used this in the end: function draw(imgData, frameCount) { var r = new FileReader(); r.readAsBinaryString(imgData); r.onload = function(){ var img=new Image(); img.onload = function() { cxt.drawImage(img, 0, 0, canvas.width, canvas.height); } img.src = “data:image/jpeg;base64,”+window.btoa(r.result); }; } I needed to read the bytes into a string before using btoa().

“Tainted canvases may not be loaded” Cross domain issue with WebGL textures

are you setting the crossOrigin attribute on your img before requesting it? var img = new Image(); img.crossOrigin = “anonymous”; img.src = “https://graph.facebook.com/1387819034852828/picture?width=150&height=150”; It’s was working for me when this question was asked. Unfortunately the URL above no longer points to anything so I’ve changed it in the example below var img = new Image(); … Read more