Break a bitmap into a grid with ActionScript 3

I needed a way to break apart a loaded bitmap into a grid of smaller bitmaps so I could then manipulate them separately. I ended up creating BitmapGrid.as, a class that will break apart your bitmaps into an array for you to do with as you please.


Download the code & example files

comments

  • http://exanimo.com matthew

    This is pretty sweet! It might be nice, though, if the spacing weren’t applied to the last column like that. Also, if the function returned a multidimensional array so you could do something like result[x][y], instead of having to figure out the index of the position you want. In any case, I can think of a lot of places where this will come in handy.

  • http://www.eightdotthree.net/ admin

    Also, if the function returned a multidimensional array so you could do something like result[x][y]

    I will implement that, should be pretty easy.

  • Uriel

    What about multiple images from a xml? All broke in squares, in a order, without any transition or slideshow.. For example, you get 12 images and cut a 40×40 square for each one and make a grid of each piece from a xml node. Is that possible?

    By the way, Thanks for the code!

  • http://www.eightdotthree.net/ admin

    I don’t see why not. BitmapGrid.breakBitmapByGrid returns an Array of Bitmaps so you could just keep on sending bitmaps to it and store the results in an Array and do what you want with it.

  • Uriel

    How do i store those results into an array? Your example is great.. but i’m not too advanced in programming..

  • http://www.dobox.com/ Bruce

    What about multiple images from a xml? All broke in squares, in a order, without any transition or slideshow.. For example, you get 12 images and cut a 40×40 square for each one and make a grid of each piece from a xml node. Is that possible?

    By the way, Thanks for the code!