PDA

View Full Version : PNG Decoder



jerion
November 9th, 2007, 07:16 PM
Hello everybody, this is my first post here, but I have been looking these forums for a while.

Here is my first attempt at decoding images. This is a small class that can decode bytearrays from png images and transfrom that bytearray to a bitmapdata. It is very limited right now, it can only decode truecolour with alpha png images with no interlacing, no filter, and bit depth of 8.

The reason I did this was to avoid using the Loader.loadBytes() method, since I needed a faster way to load lots of small png images at the same time that are read by Flash as raw bytes.

If you have any suggestions, please let me know.

Anogar
September 24th, 2008, 03:29 PM
This is actually pretty awesome. The unfortunate thing is that it's like 50x slower than loadBytes(), as far as I can tell. Heh. Good stuff though. :thumb:

Dom_
September 24th, 2008, 04:25 PM
pretty cool class

getfile
November 16th, 2008, 06:47 AM
try

hariranjit
July 15th, 2010, 03:33 AM
Can u pls guide me how to give image source in PngDecoder.as using php?
Thanks

pippy
August 5th, 2010, 04:14 AM
While this is a great script, I found it often failed on variable bit depths. After a bit of researching I found flash has an inbuilt PNG decoder, but it's asynchronous. This solution takes in two paramaters , a byte array and a callback function (that takes in a bitmapData):



package com.deadlydiddle.util {
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.utils.ByteArray;
import flash.display.Loader;
import flash.events.Event;

public class ImageDecoder
{
private var loader:Loader = new Loader();
public var loading:Boolean;

/**
* Constructor - Creates a new Image decoder
* Decodes the byte array byteData, and when done calls callBack with the BitmapData
*/
public function ImageDecoder(byteData:ByteArray, callBack:Function) {
loading = true;
loader.contentLoaderInfo.addEventListener(Event.CO MPLETE,
function(e:Event){
loading = false;
var decodedBitmapData:BitmapData = Bitmap(e.target.content).bitmapData;
callBack(decodedBitmapData);
});
loader.loadBytes(byteData);
}
}
}

garjones
December 23rd, 2011, 09:04 PM
Booyah booyah booyah.

garjones
December 23rd, 2011, 09:21 PM
Aye, have you thought about using Scaleform?