1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| const imgfillet = (ctx, img, left, top, width, height, fillet) => { // ctx 图片 起始点X Y 图片宽 高 适配单位 圆角半径 ctx.beginPath(); ctx.save(); ctx.setLineWidth(1); ctx.setStrokeStyle('#ffffff'); ctx.moveTo(left + fillet, top); // 创建开始点 ctx.lineTo(left + width - fillet, top); // 创建水平线 ctx.arcTo(left + width, top, left + width, top + fillet, fillet); // 创建弧 ctx.lineTo(left + width, top + height - fillet); // 创建垂直线 ctx.arcTo(left + width, top + height, left + width - fillet, top + height, fillet); // 创建弧 ctx.lineTo(left + fillet, top + height); // 创建水平线 ctx.arcTo(left, top + height, left, top + height - fillet, fillet); // 创建弧 ctx.lineTo(left, top + fillet); // 创建垂直线 ctx.arcTo(left, top, left + fillet, top, fillet); // 创建弧 ctx.stroke(); // 这个具体干什么用的? ctx.clip();
let bl = img.width / img.height let bl2 = width / height if (bl > bl2) { let w = Math.floor(img.width / (bl / bl2)) let sx = Math.floor((img.width - w) / 2), sy = 0, sWidth = w, sHeight = img.height ctx.drawImage(img.path, sx, sy, sWidth, sHeight, left, top, width, height); } else if (bl < bl2) { let h = Math.floor(img.height / (bl2 / bl)) let sx = 0, sy = (img.height - h) / 2, sWidth = img.width, sHeight = h ctx.drawImage(img.path, sx, sy, sWidth, sHeight, left, top, width, height); } else { ctx.drawImage(img.path, left, top, width, height); } ctx.restore(); ctx.closePath(); }
|