Revision: 55580
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at February 12, 2012 06:46 by burnandbass
Initial Code
package { import flash.display.BitmapData; import flash.display.DisplayObject; import flash.geom.Matrix; import flash.geom.Rectangle; public class SliceBitmap { public function SliceBitmap() { /* Author: Chrysto Panayotov ( burnandbass[at]gmail[dot]com ) AS3 util to slice horizontal bitmaps... The names of the static functions are self-explanary, returns array of bitmapData's */ } public static function sliceBitmap(_bitmapToSlice:DisplayObject, pieces:Number = 2, disposeOriginal:Boolean = false):Array{ var slicesArray:Array = []; var tempWidth:Number = 0; for(var i:uint = 0; i< pieces; i++){ var cropMatrix:Matrix = new Matrix(); cropMatrix.translate(-tempWidth,0); var cropRectangle:Rectangle = new Rectangle(0,0,(_bitmapToSlice.width/pieces),_bitmapToSlice.height); var tempBitmap:BitmapData = new BitmapData(_bitmapToSlice.width/pieces,_bitmapToSlice.height); tempBitmap.draw(_bitmapToSlice,cropMatrix,null,null,cropRectangle,true); tempWidth += tempBitmap.width; slicesArray.push(tempBitmap); } return slicesArray; if(disposeOriginal){ _bitmapToSlice.dispose() } } public static function sliceBitmapOffset(_bitmapToSlice:DisplayObject, pieces:Number = 2, disposeOriginal:Boolean = false,piecesOffset:Number = 2):Array{ var slicesArray:Array = []; var tempWidth:Number = 0; for(var i:uint = 0; i< pieces; i++){ var cropMatrix:Matrix = new Matrix(); cropMatrix.translate(-tempWidth,0); var cropRectangle:Rectangle = new Rectangle(0,0,(_bitmapToSlice.width - (pieces-1)*piecesOffset)/pieces,_bitmapToSlice.height); var tempBitmap:BitmapData = new BitmapData( (_bitmapToSlice.width-(pieces-1)*piecesOffset)/pieces,_bitmapToSlice.height); tempBitmap.draw(_bitmapToSlice,cropMatrix,null,null,cropRectangle,true); tempWidth += tempBitmap.width + piecesOffset; slicesArray.push(tempBitmap); } return slicesArray; if(disposeOriginal){ _bitmapToSlice.dispose() } } }//end }
Initial URL
Initial Description
just slice bitmap class, takes DisplayObject, return array of BitmapData's Can be used to do something like this: http://burnandbass.com/basstaslider
Initial Title
ActionScript 3 SliceBitmap Class
Initial Tags
Initial Language
ActionScript 3