旋转位图数据在AS3 180deg出口 [英] Rotate bitmap data in AS3 180deg for export
问题描述
我在AS3闪存的位图,我使用base64连接codeD JPG格式的字符串发送过来的JavaScript。
所有这一切的伟大工程。我需要发送的IMG在缩小,并且旋转180deg。缩放工作,但不旋转。旋转从未发生。我知道林很显然做错了,但不知道正确的方式。
所以基本上我只需要旋转图像180deg所以当它发送到JavaScript是颠倒了。
下面是我的变换code
VAR比例因子:INT = 5;
VAR tempBitmap:的BitmapData =新的BitmapData(img.width /比例因子,img.height /比例因子);
变种drawMatrix:矩阵=新的Matrix(1 /比例因子,0,0,1 /比例因子);
drawMatrix.rotate(Math.PI); // 180deg
tempBitmap.draw(IMG,drawMatrix);
我想你需要翻译旋转,否则它就会被裁剪等以后你的对象,你没有看到它,我做了一个例子,在一个影片剪辑的位图只是使用CS5的阶段。
匹配import flash.display.Bitmap;
进口flash.display.BitmapData;
进口的flash.display.MovieClip;
VAR比例因子:INT = 1;
VAR tempBitmap:的BitmapData =新的BitmapData(img.width,img.height);
VAR rotationMatrix:矩阵=新的Matrix();
rotationMatrix.rotate(Math.PI);
rotationMatrix.translate(img.width,img.height);
tempBitmap.draw(box_mc的,rotationMatrix);
VAR输出:位图=新位图(tempBitmap);
的addChild(输出);
我没惹缩放,你可以这样做你自己,我猜。一个我放在舞台右侧的位图数据得出的一个是舞台的左上角,并正确地反转。
更新
另外看看<一href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/fl/motion/MatrixTransformer.html#rotateAroundExternalPoint%28%29"相对=nofollow> fl.motion.MatrixTransformer 按如下32bitkid评论!
I have a bitmap in AS3 flash and I am sending it over to javascript using a base64 encoded jpg string.
All that works great. I need to send the img over scaled down, and rotated 180deg. The scaling works, but not the rotation. The rotation never takes. I know Im am obviously doing it wrong, but don't know the right way.
So basically I just need to rotate the image 180deg so when it is sent to javascript it is upside down.
Here is my transform code
var scaleFactor:int = 5;
var tempBitmap:BitmapData = new BitmapData(img.width/scaleFactor, img.height/scaleFactor);
var drawMatrix:Matrix = new Matrix(1/scaleFactor, 0, 0, 1 /scaleFactor );
drawMatrix.rotate(Math.PI); //180deg
tempBitmap.draw(img, drawMatrix);
I think you need to translate your object after rotation otherwise it gets clipped so you don't see it, I did an example with a bitmap in a MovieClip just on the stage using CS5.
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.MovieClip;
var scaleFactor:int = 1;
var tempBitmap:BitmapData = new BitmapData(img.width, img.height);
var rotationMatrix:Matrix = new Matrix();
rotationMatrix.rotate(Math.PI);
rotationMatrix.translate(img.width, img.height);
tempBitmap.draw(box_mc, rotationMatrix);
var output:Bitmap = new Bitmap(tempBitmap);
addChild(output);
I didn't mess with the scaling, you can do that yourself I guess. The one I put on the stage is on the right, the bitmapData drawn one is top left of stage, and correctly inverted.
UPDATE
Also have a look at fl.motion.MatrixTransformer as per 32bitkid comment below!
这篇关于旋转位图数据在AS3 180deg出口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!