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.
edit: updated rect
Comments
Post a Comment