Reputation: 1189
I'm just starting out with my first Adobe Air project (I'm a pure AS3 developer by trade). I'm planning to build an image editor which supports layers. I'm wondering what the best way would be to store an entire project including layer data (images) to a users hard disk.
I'm wondering if there is any pros/cons in creating a custom file format for my application. The idea is I will be able to store an entire project in a single file. This will be done by writing meta data to the file's header such as the image dimensions, layer names, layer data offsets etc...
I'm trying to be mindful of the issues which might arrise such as maintaining backwards compatibility after adding new project features/meta etc.
I guess I'm asking whether people have any advice or experience with creating a custom file format for Adobe Air and if there are any other 'out-of-the-box' solutions to saving 'complex' data to a users hard disk.
Thanks.
Upvotes: 1
Views: 516
Reputation: 5554
i have written a couple of custom Binary Formats for my projects. You would want to create a Header for your format with the metadata about your file first. Checkout the File Structure of an MP3 file. It might get you an insight into how to organize your file. I think your layers will correspond to MP3 Frames in the diagram as i can see that part of the data repeating.
Flex provides you an option to mark a class as [RemoteObject]
and write it to disk in a serialized form. But i found it taking too much size. I made a ByteArray and wrote the header data individually and i was able to save almost 200 bytes using this approach.
Make sure you read the documentation on ByteArray and its capabilities.
And regarding the last part, i am not aware of any out of the box solutions to save complex data to the hdd. I can provide you with more specific info if you want.
Upvotes: 0
Reputation: 51837
Probably you could do a custom binary format and write the ByteArray to disk. That should be fast and compact. I've never wrote a custom binary format, but I'm sure someone here can walk you through the best practices in that. You could save a string description of your layer's arrangements to a ByteArray using writeUTF or writeUTFBytes and you can use BitmapData's getPixels() as it returns a ByteArray.
A 'workaround' idea that comes to mind is to create an archive uzing an as3 zip package that will contain your layers as PNGs/JPEGs (probably using the image as3corelib encoders) and an xml file that describes your file(what layers should go where, with what blend/transparency/etc. ). This might be bit longwinded though.
HTH, George
Upvotes: 5