I made a function for you.
public static function pad(source:BitmapData, tileWidth:int, tileHeight:int, padding:int):BitmapData
{
var width:int = source.width + (source.width / tileWidth) * (padding * 2);
var height:int = source.height + (source.height / tileHeight) * (padding * 2);
var target:BitmapData = new BitmapData(width, height, true, 0x0);
var rect:Rectangle = new Rectangle(0, 0, tileWidth, tileHeight);
var point:Point = new Point();
var countX:int = source.width / tileWidth;
var countY:int = source.height / tileHeight;
for (var i:int = 0; i < countX; ++i)
{
for (var j:int = 0; j < countY; ++j)
{
rect.x = i * tileWidth;
rect.y = j * tileHeight;
point.x = padding * (i + 1) + padding * i + i * tileWidth;
point.y = padding * (j + 1) + padding * j + j * tileHeight;
target.copyPixels(source, rect, point);
}
}
return target;
}
This is a fairly expensive operation and will eat up a lot of memory if you have a lot of copies, so you should ideally run it once and store the result.