Skip to content

Instantly share code, notes, and snippets.

@RhinoLu
Created January 27, 2015 15:57
Show Gist options
  • Save RhinoLu/018fa8354433de5776d3 to your computer and use it in GitHub Desktop.
Save RhinoLu/018fa8354433de5776d3 to your computer and use it in GitHub Desktop.
(AS3)利用 BitmapData.draw 對位圖進行翻轉縮放操作
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_;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment