翻转画布在页面上发布后(旋转180度) [英] Flip <canvas> (rotate 180deg) after being published on page

查看:41
本文介绍了翻转画布在页面上发布后(旋转180度)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将画布元素附加到DOM之后对其进行旋转.画布是600x50,这是手头的代码:

I'm trying to rotate a canvas element AFTER it's been appended to the DOM. Canvas is 600x50 and this is the code at hand:

var canvas = document.getElementsByTagName('canvas')[2];
var ctx = canvas.getContext('2d');
ctx.translate(300, 25); // rotate @ center

ctx.rotate(angle * Math.PI/180);

未完成任务.我想念什么吗?

which isn't accomplishing the task. Am I missing something?

谢谢

推荐答案

深入研究并找到了可行的解决方案;

Dug around and found this working solution;

context.scale(1,-1); //flip vertically 
context.translate(0,-height); //move beneath original position

创造奇迹!

这篇关于翻转画布在页面上发布后(旋转180度)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆