Comments (2)
你可以单独建一个canvas
来试一下这个函数,传入canvas的context
,图片路径,长宽,和旋转角度。
function drawImageWithDegree(ctx, path, width, height, degree) {
let isVertical = degree % 180 > 0
let drawWidth = isVertical ? height : width
let drawHeight = isVertical ? width : height
let centerX = width / 2
let cneterY = height / 2
let drawCenterX = drawWidth / 2
let drawCneterY = drawHeight / 2
let d = Math.abs(width - height) / 2
// ctx.translate(drawCenterX, drawCneterY)
// ctx.rotate(degree * Math.PI / 180)
// ctx.translate(-drawCenterX, -drawCneterY)
ctx.translate(centerX, cneterY)
ctx.rotate(degree * Math.PI / 180)
ctx.translate(-centerX, -cneterY)
// ctx.translate(-d, d)
if (isVertical) {
if (drawHeight > drawWidth) {
ctx.drawImage(path, d, -d, drawWidth, drawHeight)
}
else {
ctx.drawImage(path, -d, d, drawWidth, drawHeight)
}
}
else {
ctx.drawImage(path, 0, 0, drawWidth, drawHeight)
}
ctx.draw(false, function (e) {
console.log('draw callback')
})
}
因为默认是以(0, 0)
为旋转中心的,我将其转换到图片中心位置,然后进行绘制图片。
ctx.translate(centerX, cneterY)
ctx.rotate(degree * Math.PI / 180)
ctx.translate(-centerX, -cneterY)
from welcropper.
好的 非常感谢
from welcropper.
Related Issues (20)
- 不知有无这个bug?
- 这个可以实现截屏的功能吗?或者指定区域截取 HOT 1
- 截图完的图片不清晰,文字变模糊 HOT 3
- 原图按钮不是选原图 HOT 3
- 菜单-原图,是什么效果?为什么没有反应
- 截图生成的图片和原图的清晰度是一样的吗,还是会模糊一点 HOT 1
- 请问下为什么选原图 图片会比原图大很多 HOT 3
- 拍照后图片不显示 HOT 3
- 安卓手机经常拍照或者选图后退出来,请问这个要什么解决。 HOT 1
- 如何固定正方形? HOT 10
- 有的图片旋转后蒙层只显示部分 HOT 3
- 大佬canvas可以截屏吗 HOT 1
- movable-area改变长宽后,movable-view移动区域大小没变
- 图片旋转后截图阴影显示不全 HOT 1
- 整个截图框移动可以实现? HOT 2
- 图片大的情况下导致小程序自动关闭 HOT 14
- component形式可以用吗? HOT 3
- Component版的在iPhone6s上movable-view有问题,小米4C没问题。 HOT 1
- 根节点scroll-view有其他用意? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from welcropper.