var c:Sprite = new Sprite;
c.x = 200;
addChild(c);
var s:Sprite = new Sprite;
s.graphics.beginFill(0xff0000);
s.graphics.drawRect(0,0,100,100);
s.graphics.endFill();
s.graphics.beginFill(0x00ff00);
s.graphics.drawRect(100,0,100,100);
s.graphics.endFill();
c.addChild(s);
//s.scaleX = -1;
package org.easily.utils
{
import flash.display.BitmapData;
import flash.geom.Matrix;
public class BitmapDataUtils
{
//水平翻转一个位图
public static function flipHorizontal(bmpData:BitmapData, transparent:Boolean = true, fillColor:uint = 0):BitmapData
{
var matrix:Matrix = new Matrix();
matrix.a = -1;
matrix.tx = bmpData.width;
var bmpData_:BitmapData = new BitmapData(bmpData.width, bmpData.height, transparent, fillColor);
bmpData_.draw(bmpData, matrix);
return bmpData_;
}
//垂直翻转一个位图
public static function flipVertical(bmpData:BitmapData, transparent:Boolean = true, fillColor:uint = 0):BitmapData
{
var matrix:Matrix = new Matrix();
matrix.d = -1;
matrix.ty = bmpData.height;
var bmpData_:BitmapData = new BitmapData(bmpData.width, bmpData.height, transparent, fillColor);
bmpData_.draw(bmpData, matrix);
return bmpData_;
}
//缩放位图
public static function scaleBitmapData(bmpData:BitmapData, scaleX:Number, scaleY:Number):BitmapData
{
var matrix:Matrix = new Matrix();
matrix.scale(scaleX, scaleY);
var bmpData_:BitmapData = new BitmapData(scaleX * bmpData.width, scaleY * bmpData.height, true, 0);
bmpData_.draw(bmpData, matrix);
return bmpData_;
}
}
}