Created
May 12, 2015 07:50
-
-
Save marchbold/db1be6a7861f79e2ad58 to your computer and use it in GitHub Desktop.
Parse WebP data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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