温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

HTML5 Canvas实现的图片马赛克模糊特效

发布时间:2020-08-05 03:55:20 来源:网络 阅读:603 作者:失落的心情 栏目:移动开发

要想让图片像素化,首先调用如下脚本:
<script type="text/javascript" src="https://cache.yisu.com/upload/information/20200218/42/4254.jpg" width="300" height="426" />

在你的脚本中使用closePixelate方法与图片上,你可以通过一组数组选项控制图片输出。如下示例代码:
document.getElementById('pixelExample2').closePixelate( [
{ resolution: 24 }
] );


html代码如下:
复制代码

<!doctype html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>基于HTML5 Canvas实现的图片马赛克模糊特效-何问起</title>
<link rel="stylesheet" type="text/css" href="1/css/normalize.css" />
<link rel="stylesheet" type="text/css" href="1/css/default.css">
<style type="text/css">
.thumb
{
margin-left: 5em;
}
.thumb img
{
max-width: 400px;
}
</style>
</head>
<body>
<div >
<h3>基于HTML5 Canvas的图片马赛克模糊特效 何问起</h3>
<a href="http://hovertree.com">首页</a> <a href="http://hovertree.com/hvtart/bjae/160ced36cb3a6a86.htm">原文</a> <a href="http://hovertree.com/texiao/html5/1/tupianmohu.rar" target="_self">下载</a>
<a href="https://cache.yisu.com/upload/information/20200218/42/4255.jpg" id="dolly1" />
<img src="1/img/2.jpg" id="dolly2" />
<img src="1/img/3.jpg" id="dolly3" />
</div>
</div>
</div>
<script src="http://hovertree.com/texiao/html5/1/js/close-pixelate.js"></script>
<script>
window.onload = function () {
var dolly1 = document.getElementById('dolly1')
var dolly2 = document.getElementById('dolly2')
var dolly3 = document.getElementById('dolly3')
var pixelOpts = [{ resolution: 8}]
var pixelDolly1 = dolly1.closePixelate(pixelOpts)
var pixelDolly2 = dolly2.closePixelate(pixelOpts)
var pixelDolly3 = dolly3.closePixelate(pixelOpts)
var range = document.getElementById('range')
var output = document.getElementById('output')

range.addEventListener('change', function (event) {
var res = parseInt(event.target.value, 10)
res = Math.floor(res / 2) * 2
res = Math.max(4, Math.min(100, res))
output.textContent = res
// console.log( res );
pixelOpts = [{ resolution: res}]
pixelDolly1.render(pixelOpts)
pixelDolly2.render(pixelOpts)
pixelDolly3.render(pixelOpts)
}, false)
}
</script>
</body>
</html>

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI