问答详情
源自:3-3 建立交互逻辑

show()不起作用

var canvasWidth = 800;

var canvasHeight = 600;


var canvas = document.getElementById('canvas');

var context = canvas.getContext('2d');


canvas.width = canvasWidth;

canvas.height = canvasHeight;


var image = new Image();

image.src = 'blur.jpg';

var clippingRegion = {

x: 400,

y: 200,

r: 50

}


image.onload = function(e){

initCanvas();

}


function initCanvas(){

draw(image, clippingRegion);

}


function setClippingRegion(clippingRegion){

context.beginPath();//每当开始绘制新路径

context.arc(clippingRegion.x, clippingRegion.y, clippingRegion.r, 0, Math.PI*2, false);//绘制圆

context.clip();//剪辑区域

}


function draw(image, clippingRegion){

context.clearRect(0, 0, canvas.width, canvas.height);

setClippingRegion(clippingRegion);

context.save();

context.drawImage(image, 0, 0, 800, 600);

context.restore();

}


function show(){

clippingRegion.r = 1000;

draw(image, clippingRegion);

}


提问者:阿卡林 2016-03-05 16:15

个回答

  • 柯kk
    2019-05-05 13:31:48

    感谢,遇到了同样的问题

  • 阿卡林
    2016-03-06 09:20:36

    知道了setClippingRegion(clippingRegion);没写在context.save()后面