Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/LeeBurrows/Async-Image-Encoders
Asynchronously encode BitmapData objects into image file format
https://github.com/LeeBurrows/Async-Image-Encoders
actionscript encoding-library image
Last synced: 3 months ago
JSON representation
Asynchronously encode BitmapData objects into image file format
- Host: GitHub
- URL: https://github.com/LeeBurrows/Async-Image-Encoders
- Owner: LeeBurrows
- License: mit
- Created: 2013-01-27T19:39:20.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2013-08-28T01:33:06.000Z (about 11 years ago)
- Last Synced: 2024-05-03T06:22:47.302Z (6 months ago)
- Topics: actionscript, encoding-library, image
- Language: ActionScript
- Size: 278 KB
- Stars: 20
- Watchers: 7
- Forks: 7
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-actionscript-sorted - Async-Image-Encoders - Asynchronously encode BitmapData objects into image file format (Multimedia / Image)
README
#Asynchronous Image Encoders
##ActionScript 3 classes for asynchronously encoding BitmapData source into image file formats
Encodes BitmapData objects over multiple frames to avoid freezing the UI. Ideally suited for mobile AIR where ActionScript Workers are unavailable.
Specify milliseconds per frame to allocate to encoding. Stop processing at any time.
Current supported file formats:
* .JPG
* .PNG
* .BMPOthers can be added by sub-classing AsyncImageEncoderBase to implement asynchronous processing.
See ASDocs for further details on implementing your own encoders.A simple usage example:
package
{
import com.leeburrows.encoders.AsyncPNGEncoder;
import com.leeburrows.encoders.supportClasses.AsyncImageEncoderEvent;
import com.leeburrows.encoders.supportClasses.IAsyncImageEncoder;
import flash.display.BitmapData;
import flash.display.Sprite;
public class PNGEncoderExample extends Sprite
{
private var encoder:IAsyncImageEncoder;
public function PNGEncoderExample()
{
//generate a BitmapData object to encode
var myBitmapData:BitmapData = new BitmapData(1000, 1000, true, 0x80FF9900);
//create a new PNG encoder
encoder = new AsyncPNGEncoder();
//add progress and complete listeners
encoder.addEventListener(AsyncImageEncoderEvent.PROGRESS, encodeProgressHandler);
encoder.addEventListener(AsyncImageEncoderEvent.COMPLETE, encodeCompleteHandler);
//start encoding for 20 milliseconds per frame
encoder.start(myBitmapData, 20);
}
private function encodeProgressHandler(event:AsyncImageEncoderEvent):void
{
//trace progress
trace("encoding progress:", Math.floor(event.percentComplete)+"% complete");
}
private function encodeCompleteHandler(event:AsyncImageEncoderEvent):void
{
encoder.removeEventListener(AsyncImageEncoderEvent.PROGRESS, encodeProgressHandler);
encoder.removeEventListener(AsyncImageEncoderEvent.COMPLETE, encodeCompleteHandler);
//trace size of result
trace("encoding completed:", encoder.encodedBytes.length+" bytes");
//do something with the bytes...
//..save to filesystem?
//..upload to server?
//..set as source for flex Image component?
}
}
}
###Version History###* v1.0.1
+ Initial build.* v1.0.2
+ Fixed issue #001 : Validate start() BitmapData Argument.
+ Fixed issue #002 : Consolidate Events.
+ Fixed issue #003 : Private _encodedBytes Property Exposed Via Reference.* v1.0.3
+ ASDocs inserted into SWC to facilitate IDE code hinting.* v1.0.4
+ Added dispose() method.
+ Fixed issue #004 : Unnecessary memory retention.