先在HTML中创建 img和canvas并设置id属性

<canvas id="canvas" width="500" height="500" style="border: 1px solid red;"></canvas>

<img src="./dialog.png" id="img" />

js中

  微信小程序也可以使用。

  当然获取canvas会不一样。微信小程序获取canvas,参考(https://www.cnblogs.com/1748sb/p/12955714.html)。

  画圆采用'yiven'博主的:https://www.cnblogs.com/yiven/p/7551535.html 。

let c=document.getElementById('canvas');
let img=document.getElementById('img')
let context=c.getContext('2d');
// 图片加载
img.onload = function(e){
console.log('图片加载成功',e)
drawRoundedImg(50,100,100,100,50,img);
}
// 你会需要一张背景
function backGround(){
context.save();
context.fillStyle="#FFFFFF"
context.fillRect(x,y,w,h);
context.restore();
}
// 你可能还需要生成一些文字
function text(){
context.save();
context.fillStyle="black";
context.font="25px 微软雅黑";
context.fillText('踏步走',x,y); // 名字
context.restore();
}
// 生成一张圆在插入图片
function drawRoundedImg(x,y,w,h,r,bgimg){
context.save();
context.beginPath();
context.moveTo(x+r,y);
context.arcTo(x+w,y,x+w,y+h,r);
context.arcTo(x+w,y+h,x,y+h,r);
context.arcTo(x,y+h,x,y,r);
context.arcTo(x,y,x+w,y,r);
context.lineWidth = 1;//线条的宽度
context.strokeStyle = "red";//线条的颜色
context.stroke();
context.clip();
context.drawImage(bgimg, x, y, w, h);
context.restore();
context.closePath();
}

  

生成后

  

最新文章

  1. Scrapy框架实现爬虫
  2. MongoDB的配置、启动、关闭
  3. nuget github host
  4. 如何对SQL Server 2005进行设置以允许远程连接(转载)
  5. 【课程分享】基于Lucene4.6+Solr4.6+Heritrix1.14+S2SH实战开发从无到有垂直搜索引擎
  6. NIO学习:buffer读入与写出(文件复制示例)
  7. HDU 2502 月之数(简单递推)
  8. mac 终端常见指令
  9. UVA - 10098 - Generating Fast (枚举排列)
  10. C 文件直接包含
  11. JAVA设计模式:代理模式
  12. sphinx随笔记了一下
  13. PHP7的新功能
  14. 补习系列(15)-springboot 分布式会话原理
  15. Python strip()与lstrip()、rstrip()
  16. JMeter 连接 sql server
  17. saltstack SLS
  18. Python3网络爬虫(四):使用User Agent和代理IP隐藏身份《转》
  19. nslookup debug
  20. Dart async proc

热门文章

  1. requests和正则表达式爬取猫眼电影Top100练习
  2. [POI2010]PIL-Pilots 单调队列
  3. 安装memcache,步骤
  4. Axure实现vcg官网首页原型图
  5. Linux操作系统的基本介绍
  6. 【C语言C++编程入门】——程序结构:构思!
  7. 并查集算法Union-Find的思想、实现以及应用
  8. go 正则 爬取邮箱代码
  9. centos8平台使用ab做压力测试
  10. 电子阅读器.vbs