Skip to content

Instantly share code, notes, and snippets.

@marchbold
Created May 12, 2015 07:50
Show Gist options
  • Save marchbold/db1be6a7861f79e2ad58 to your computer and use it in GitHub Desktop.
Save marchbold/db1be6a7861f79e2ad58 to your computer and use it in GitHub Desktop.
Parse WebP data
try
{
WebP.init( APPLICATION_KEY );
if (WebP.isSupported)
{
// For this example load data from a file into a ByteArray
var file:File = File.applicationDirectory.resolvePath( "image.webp" );
var fs:FileStream = new FileStream();
fs.open( file, FileMode.READ );
var data:ByteArray = new ByteArray();
fs.readBytes( data, 0, fs.bytesAvailable );
fs.close();
var decodedData:ByteArray = new ByteArray();
//
// Use WebP to decode the data
var success:Boolean = WebP.service.parseWebP( data, decodedData );
if (success)
{
var rect:Rectangle = new Rectangle( 0, 0, WebP.service.width, WebP.service.height );
var bd:BitmapData = new BitmapData( WebP.service.width, WebP.service.height, true );
bd.setPixels( rect, decodedData );
// Use the BitmapData as required
}
}
}
catch (e:Error)
{
}
// com.distriqt.WebP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment