javascript - Canvas rectangle background image -


i want set background image rectangle in canvas. far i've done this.

var img = new image()     img.src = //source of image. var newpattern = ctx.createpattern(img, "no-repeat"); ctx.fillstyle = newpattern; 

and works, problem is, applies image canvas, not rectangle.

and whenever change position of rectangle, image remains in same position.

can suggest how fix this, image'd attached rectangle.

if want draw image within specified rectangle can this.

context.rect(x, y, width, height); context.clip(); context.drawimage(img, 0, 0); 

this creates rectangle @ (x, y) size (width, height) used future calls context. if want stop clipping need add a

context.save(); 

before code above , a

context.restore(); 

after have drawn image.

jsfiddle

edit: updated rect


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -