Created
January 27, 2015 15:57
-
-
Save RhinoLu/018fa8354433de5776d3 to your computer and use it in GitHub Desktop.
(AS3)利用 BitmapData.draw 對位圖進行翻轉縮放操作
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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