I'm making a program for myself that can open unarranged sprite sheets, arrange them according to an XML file, and then save them as PNGs. What it does is it loads the unarranged sheet and puts it in a `BitmapData`, then according to a specific XML file it grabs each frame on the sheet (using `BitmapData.copypixels()`), and adds the resulting `Bitmap` to an array in order. Then it arranges them by adding these `Bitmap`s to a `Sprite` object, making new lines accordingly. In essence, what I end up with is a `Sprite` containing `Bitmaps` that are arranged how I want them.

Now what I normally do from here is draw the `Sprite` onto a `BitmapData` using `BitmapData.draw()`, which works, and then I go on to encode it as a PNG and save it. This all works, except for in one case.
Sometimes I make one arranged spritesheet out of multiple unorganised ones, which results in a fairly large sheet. In one case this resulting sheet is extremely large, and for some reason the `BitmapData` that I want to draw to just won't accept being that large. That is, I create a new `BitmapData`, with dimensions equal to the `Sprite`, but when I try to do that I get this error:

```
ArgumentError: Error #2015: Invalid BitmapData.

```

As far as I know this only happens if I make a `BitmapData` with a width and/or height of 0, or if I exceed the maximum dimensions. I'd think it was the latter if it wasn't for the fact that Flash 11 and AIR 3 don't have a limit.

In any case I haven't found a way out of it, so basically this is my question: is there any way to do this differently? For example, can I get the pixel data of a `Sprite` without making a `BitmapData`? Or, can I somehow store the data in a `BitmapData` without having to give it the same dimensions as the image? Or is there some different way to do this altogether?

I realise I can split up the image into 2 separate `BitmapData`s, but I want to know if there's an alternative before resorting to this.

By the way, if it matters, it's an Adobe AIR app made using FlashDevelop and the Flex 4 SDK. I'm using [PNGEncoder2](https://github.com/cameron314/PNGEncoder2) to encode the final sprite sheet that I save.

EDIT: I have discovered that the problem seemed to be that my PC simply can't handle a `BitmapData` of the required size. I tried splitting it into two separate `BitmapData`s, but unfortunately when creating the second `BitmapData` I received the same error. Therefore it simply seems that that amount of data cannot be contained in my PC's memory as `BitmapData`s at one time. Unfortunately this means that I can't even use g10's solution of merging two `BitmapDatas` into a single PNG using the PNG encoder he linked to.
My solution so far has been to store draw half of the image into a `BitmapData`, encode it, then `dispose()` the `BitmapData` and store the second half in it and encode that. Then I save the `ByteArrays` (which are the result of the encoding) as separate images, which I can reconstruct into one using an external program.

So now, my question is more "can I somehow save this as a single PNG" rather than "can I get it as a single `BitmapData`".