캔버스에서 이미지가 위에서 아래로 이동하는 기본 HTML5 이미지 슬라이더를 만들었습니다. 모든 이미지를 5도 각도로 회전시키고 싶습니다. 그것을 시도했을 때 캔버스에 약간의 왜곡이 있고 이미지가 제대로 회전되지 않은 것 같습니다.캔버스 이미지 회전 문제
나는 아래의 게시물에서 언급 한 회전 방법을 시도했습니다 바이올린
How do I rotate a single object on an html 5 canvas?
- http://jsfiddle.net/DS2Sb/코드 여기
this.createImage = function (image, width, height) {
var fbWallImageCanvas = document.createElement('canvas');
var fbWallImageCanvasContext = fbWallImageCanvas.getContext('2d');
fbWallImageCanvas.width = width;
fbWallImageCanvas.height = height;
fbWallImageCanvasContext.save();
fbWallImageCanvasContext.globalAlpha = 0.7;
this.rotateImage(image, 0, 0, width, height, 5, fbWallImageCanvasContext);
fbWallImageCanvasContext.drawImage(image, width, height);
fbWallImageCanvasContext.restore();
return fbWallImageCanvas;
};
this.rotateImage = function (image, x, y, width, height, angle, context) {
var radian = angle * Math.PI/180;
context.translate(x + width/2, y + height/2);
context.rotate(radian);
context.drawImage(image, width/2 * (-1), height/2 * (-1), width, height);
context.rotate(radian * (-1));
context.translate((x + width/2) * (-1), (y + height/2) * (-1));
};
코드는 오프 스크린 캔버스에 두 번 이미지를 그릴 것입니다 : 하나는 회전, 하나는 회전하지 않습니다. 코드에서 원하는 것입니까? – markE