跳至主要內容
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?

4563博客

全新的繁體中文 WordPress 網站
  • 首頁
  • canvas 使用 Affine,实现任意点变换(旋转,位移,缩放
未分類
18 4 月 2021

canvas 使用 Affine,实现任意点变换(旋转,位移,缩放

canvas 使用 Affine,实现任意点变换(旋转,位移,缩放

資深大佬 : zoule 7

矩阵入门教程及文件获取地址

http://www.seeshiontech.com/docs/page_145.html

1.首先我们创建 canvas 标签,为了方便查看效果,我们为 canvas 添加一下样式,这里图片我使用的是 1920*1080 的尺寸

<canvas id="canvas" width="1920" height="1080"></canvas> 
 canvas {             display: block;             border: 1px solid;             width: 480px;             height: 270px;             margin: 100px auto;         } 
 //不做处理 将图片绘制到画布  let image = document.createElement("img");         let context = canvas.getContext("2d");         image.src = "http://static.atvideo.cc/veleap/templateDemo/2021/04/06/16/30aawseyhgae.png";         image.onload = function () {             context.drawImage(                 image,                 0,                 0,             );         } 

canvas 使用 Affine,实现任意点变换(旋转,位移,缩放

2.引入 Affine.js 文件

<script src="./lib/Affine.js"></script> 

3.使用矩阵中心点旋转缩放

 let image = document.createElement("img");         let context = canvas.getContext("2d");         image.src = "http://static.atvideo.cc/veleap/templateDemo/2021/04/06/16/30aawseyhgae.png";         image.onload = function () {             const imageWidth = image.width,                 imageHeight = image.height,                 centerPointX = imageWidth / 2,                 centerPointY = imageHeight / 2;             let a = {                 x: centerPointX,                 y: centerPointY,             },                 p = {                     x: centerPointX,                     y: centerPointY,                 },                 s = {                     x: 0.5,                     y: 0.5,                 },                 r = 45;              let matrix = new Affine();             matrix.set(a, p, s, r);             context.setTransform(matrix.mA, matrix.mB, matrix.mC, matrix.mD, matrix.mE, matrix.mF);             context.drawImage(                 image,                 0,                 0,             );         } 

canvas 使用 Affine,实现任意点变换(旋转,位移,缩放

大佬有話說 (0)

文章導覽

上一篇文章
下一篇文章

AD

其他操作

  • 登入
  • 訂閱網站內容的資訊提供
  • 訂閱留言的資訊提供
  • WordPress.org 台灣繁體中文

51la

4563博客

全新的繁體中文 WordPress 網站
返回頂端
本站採用 WordPress 建置 | 佈景主題採用 GretaThemes 所設計的 Memory
4563博客
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?
在這裡新增小工具