Scale 9 Image extension


(vozochris) #1

Hello!

I wrote a Flashpunk extension: Scale9Image available as gist. Scale9Image is an extended Image.

Constructor:

  • Scale9Image(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

  • clipRect - Rectangle

  • W - int -> Image width

  • H - int -> Image height

  • disposeRegions - Boolean -> If regions should dispose after creating the image, if you plan to redraw it to another size later or often, I recommend to disable it.

How to use:

  • For example you have a 13x13 scale 9 / slice 9 button image as ButtonBitmapData:

  • var buttonImage:Scale9Image = new Scale9Image(ButtonBitmapData, new Rectangle(6, 6, 1, 1), null, 100, 20, true);

  • This code will create a 100x20 Image out of 13x13 BitmapData with 6x6 each border and 1x1 pattern-scaling pixel.

Please reply a feedback.