1 Star 0 Fork 0

zzy1661/canvas-img-analyze

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
sawtooth.html 1.09 KB
一键复制 编辑 原始数据 按行查看 历史
zzy1661 提交于 2018-10-12 19:07 . 增加canvas实现图片锯齿
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>canvas 图片锯齿</title>
<style type="text/css">
body {
background: #D3D3D3;
}
canvas {
border: 1px solid;
}
</style>
</head>
<body>
<canvas id="MyCanvas">
</canvas>
<script type="text/javascript">
var c = document.getElementById("MyCanvas"),
cxt = c.getContext("2d"),
image = new Image();
var r = 5;//锯齿半径
image.src = "http://placeimg.com/200/400/any/sepia";
image.onload = function() {
c.width = image.width;
c.height = image.height;
cxt.drawImage(this, 0, 0);
cxt.globalCompositeOperation = 'xor';
//上部
for(var i=r*2;i<c.width-r;i+=r*4) {
drawSawtooth(i,0,r,1);
}
//下部
for(var i=r*2;i<c.width-r;i+=r*4) {
drawSawtooth(i,c.height,r,0);
}
}
function drawSawtooth(x,y,r,d) { //d:方向
cxt.fillStyle='rgb(0,0,0)';
cxt.beginPath();
if(d==1) {
cxt.arc(x,y,r,Math.PI,0,true);
}else {
cxt.arc(x,y,r,0,Math.PI,true);
}
cxt.closePath();
cxt.fill();
}
</script>
</body>
</html>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
HTML
1
https://gitee.com/zzy1661/canvas-img-analyze.git
git@gitee.com:zzy1661/canvas-img-analyze.git
zzy1661
canvas-img-analyze
canvas-img-analyze
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385