show()不起作用

来源:3-3 建立交互逻辑

阿卡林

2016-03-05 16:15

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);

}


写回答 关注

2回答

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

    感谢,遇到了同样的问题

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

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

Canvas玩儿转红包照片

教你玩儿转微信红包照片模糊效果,图像展示效果,深入了解canvas

55911 学习 · 67 问题

查看课程

相似问题