Break a bitmap into a grid with ActionScript 3

December 27th, 2009

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.


The Flash plugin is required to view this object.

Download the code & example files

6 Comments »

  1. 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.

    Comment by matthew — December 28, 2009 @ 9:04 am

  2. 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.

    Comment by admin — December 29, 2009 @ 8:36 am

  3. 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!

    Comment by Uriel — May 6, 2010 @ 8:28 pm

  4. 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.

    Comment by admin — May 7, 2010 @ 6:59 am

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

    Comment by Uriel — May 8, 2010 @ 11:08 am

  6. 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!

    Comment by Bruce — May 19, 2010 @ 9:46 am

RSS feed for comments on this post. TrackBack URI

Leave a comment