Canvas Image editor

江枫思渺然 提交于 2019-12-13 19:22:01

问题


I'm trying to make an image editor with canvas, but I ran into some problems with re-sizing an rotated image. My re-size anchors and the image do not seem to line up as they should.

http://jsbin.com/isexig/9/edit#source

(The image will rotate when you click on it, its just for testing the re-sizing)

any clues how to fix this?

I found out that the angle needed to be divided by pi but i fail to get the bl to work and the anchors still do not match up perfectly =/


回答1:


I found that the group is already rotated, including the corner handles, so you don't need any trigonometry at all:

http://jsbin.com/abejab/5/edit

switch (activeAnchor.name) {
case "tl":
case "br":
    bl.x = tl.x;
    bl.y = br.y;
    tr.x = br.x;
    tr.y = tl.y;
    break;
case "tr":
case "bl":
    br.x = tr.x;
    br.y = bl.y;
    tl.x = bl.x;
    tl.y = tr.y;
    break;
}
image.x = tl.x;
image.y = tl.y;
image.width = tr.x - tl.x;
image.height = bl.y - tl.y;


来源:https://stackoverflow.com/questions/9454278/canvas-image-editor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!