I wrote a Flashpunk extension: Scale9Image available as gist.
Scale9Image is an extended Image.
1Scale9Image(source:*, scale9Grid:Rectangle, clipRect:Rectangle = null, W:int = -1, H:int = -1, disposeRegions:Boolean = true)
source– BitmapData or Class same as normal Image
scale9Grid– Rectangle -> Scale 9 grid
W– int -> Image width
H– int -> Image height
disposeRegions– Boolean -> If regions should dispose after creating the image, if you plan to
redrawit to another size later or often, I recommend to disable it.
How to use:
- For example you have a 13×13 scale 9 / slice 9 button image as ButtonBitmapData:
1var buttonImage:Scale9Image = new Scale9Image(ButtonBitmapData, new Rectangle(6, 6, 1, 1), null, 100, 20, true);
- This code will create a 100×20 Image out of 13×13 BitmapData with 6×6 each border and 1×1 pattern-scaling pixel.