There could be a case that while developing application in Flash or Flex for mobile devices, you need to capture a bitmap image and save it to the Mobile File system. While it is possible directly through the CameraRoll Class, it doesn’t have the option to save the file with a pre-defined name. This makes it difficult to access the image later.
Though there are few workarounds available for this where people have mentioned to access get the last modified image from the CameraRoll just after saving it, I don’t find it worth.
So as an alternative you could save the image to the mobile file system by writing BitmapData’s ByteArray. So in order to do so you can follow one of the following methods for getting BitmapData:
- Using AS3CoreLib: AS3CoreLib is a set of util classes which have classes for JPG or PNG encoding the images. But I have found this method to be the most time consuming while generating the ByteArray. Using this for getting a large image of few thousand pixels can make your mobile application freeze down for a while. So try to avoid this metod if possible.
- Using Alchemy implementation of C Code: Adobe’s Alchemy technology enables us to port an existing piece of C/C++ code to use in AS3 applications. One such port is available for JPEG encoding. It provides comparatively faster image encoding and ByteArray generation as compared to the AS3CoreLib. More details on this could be found here: http://segfaultlabs.com/devlogs/alchemy-asynchronous-jpeg-encoding-2
- Using the Bitmap.encode() method in AIR 3.3: This is by far the fastest method to encode an image into ByteArray. This has been added in AIR 3.3 and Flash Player 11.3. Bitmap.encode() provides option to encode an image as JPG or PNG into ByteArray using in a fast manner.