I need to display the image in progressive JPEG format ( http://en.wikipedia.org/wiki/JPEG#JPEG_compression , not to be confused with progressive display of sequential JPEG). Flash supports loading of progressive JPEG, but I have no idea how to display it during the loading. Brief googling gives me progressive loading of sequential JPEG and nothing else.
Display progressive JPEG in Flash during the loading
Asked Answered
It would go something like this:
// the loader containing the image
var loading:Boolean = false;
var loader:Loader = new Loader();
addChild(loader);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, function() {
loading = false;
trace(loader.width, loader.height);
});
var bytes:ByteArray = new ByteArray();
var stream:URLStream = new URLStream();
stream.addEventListener(ProgressEvent.PROGRESS, onProgress);
stream.addEventListener(Event.COMPLETE, onProgress);
stream.load(new URLRequest(imageURL));
function onProgress(e:Event):void {
stream.readBytes(bytes, bytes.length);
if((bytes.length > 4096 && !loading) || e.type == Event.COMPLETE) {
loading = true;
loader.loadBytes(bytes);
}
}
Notice that the loadBytes process is asynchronous. Also, when you try it with an unparseable bytearray (usually the first calls to onProgress, when there's not enough image data to process) it fails silently, so you need to somehow guarantee that you have enough data... in this case I used if(bytes.length > 4096) ;)
Your solution loads the image but fails to determine its actual dimensions. –
Voltz
You should be able to get the image dimensions on the first complete event of the loader.contentLoaderInfo ;) –
Spillage
© 2022 - 2024 — McMap. All rights reserved.