文章详情页
javascript - 如何消除canvas边缘锯齿
浏览:206日期:2022-11-30 10:39:02
问题描述
如题:我做了一个canvas图形,出现了边缘锯齿
有搜到一个:Bicubic Interpolation的插值算法,但是看不懂,请大神指点Orz!!
问题解答
回答1:可以先试试将canvas的分辨率提高一倍看一看。假设显示大小为 w * h:
将canvas的width和height设为2w和2h
将canvas的style中的width和height设为w和h
回答2:我看了一些比较好的插件,如echarts(百度图表),但是1万多行代码,实在是看不了,最后找到了一个解决方法https://www.zhihu.com/questio...let width = canvas.width,height=canvas.height;if (window.devicePixelRatio) {
canvas.style.width = width + 'px'; canvas.style.height = height + 'px'; canvas.height = height * window.devicePixelRatio; canvas.width = width * window.devicePixelRatio; ctx.scale(window.devicePixelRatio, window.devicePixelRatio);
}谨此分享给遇到同样问题的童鞋
标签:
JavaScript
相关文章:
1. javascript - vue组件通过eventBus通信时,报错a.$on is not a function2. python3.x - python3.5.2安装时make报错求助3. html - vue项目中用到了elementUI问题4. javascript - 在使用 vue.js element ui的时候 怎么样保留table翻页后check的值?5. mysql_replication - mysql读写分离时如果单台写库也无法满足性能怎么解决6. ionic 项目 ionic build android -release 打包时报错7. linux - ubuntu 命令行中文 显示菱形,期望通过引入字体解决而不是zhcon这种方式8. angular.js - 如何控制ngrepeat输出的个数9. mac里的docker如何命令行开启呢?10. python - 如何用pandas处理分钟数据变成小时线?
排行榜

网公网安备