Flex Matrix 将图像旋转 n 度
我怎样才能旋转图像,例如。使用矩阵顺时针旋转 180 度
我可以使用以下代码将图像旋转 90 度,但它是增量的,这意味着
var matrix:Matrix = new Matrix();
matrix.rotate(Math.PI/2);
matrix.tx = imgControl.content.height;
var bitmapData:BitmapData = new BitmapData(imgControl.content.height, imgControl.content.width);
bitmapData.draw(imgControl.content, matrix);
imgControl.source = new Bitmap( bitmapData);
每次运行代码时图像都会旋转 +90 度。
我想要的不是每次增加90,而是明确地说旋转180,旋转90等等。
我不熟悉矩阵,但我想它确实进行了真正的位图数据操作,而不仅仅是例如。旋转图像组件框(如果我错了请逮捕我)。
如果是这样,我想每次执行旋转命令时都必须重置图像。
我错过了什么吗?
预先感谢
Ran 的任何建议和提示
How can I rotate an Image eg. 180 degrees clockwise using the Matrix
I can use the following code to rotate the image 90 degrees, but it is incremental, meaing
var matrix:Matrix = new Matrix();
matrix.rotate(Math.PI/2);
matrix.tx = imgControl.content.height;
var bitmapData:BitmapData = new BitmapData(imgControl.content.height, imgControl.content.width);
bitmapData.draw(imgControl.content, matrix);
imgControl.source = new Bitmap( bitmapData);
Each time I run the code the image is rotated +90 degrees.
What I want is not to increment by 90 each time, but explicit say rotate 180, rotate90 and so on.
I am not familiar with the Matrix, but I guess it does real bitmapdata manipulation rather than just eg. rotate the Image component box (arrest me if I am wrong).
If so, I guess I have to reset the image each time I do the rotate command.
Am I missing something?
Thanks in advance for any advice and tips
Ran
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该矩阵不进行真正的位图数据操作。
正是
bitmap.draw
调用将 imgcontrol.content 的旋转图像绘制到位图中,之后您的代码用旋转图像覆盖 imgcontrol.content 。因此,由于您的代码目前处于站立状态,是的,您要么必须在每次旋转之前从头开始刷新图像,要么必须跟踪变量中的旋转并计算还需要旋转多少次才能到达所需的旋转。
如果需要一步进行多次90度旋转,则替换
为
The matrix does no real bitmapdata manipulation.
It is the
bitmap.draw
call that draws the rotated image of the imgcontrol.content into the bitmap, after which your code overwrites imgcontrol.content with the rotated image.So as your code is currently standing, yes, you either have to refresh the image from scratch before every rotation, or you will have to keep track of the rotations in a variable and calculate how many more times you have to rotate to get to the desired rotation.
If you need to do multiple 90 degrees rotation in one step, then replace
with