加载过程中在Flash中显示渐进式JPEG

8
我需要以渐进式JPEG格式显示图像(与顺序JPEG的渐进显示不同,详情请参见http://en.wikipedia.org/wiki/JPEG#JPEG_compression)。Flash支持加载渐进式JPEG,但我不知道如何在加载过程中显示它。简短的搜索只给出了顺序JPEG的渐进加载,没有其他信息。

你的意思是像这里问的那样吗?https://dev59.com/40rSa4cB1Zd3GeqPXY5N - Jason Sturges
1个回答

4
它可能是这样的:
// 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);
    }
}

请注意,loadBytes过程是异步的。当您尝试使用无法解析的字节数组(通常在第一次调用onProgress时,当没有足够的图像数据来处理时)时,它会默默地失败,因此您需要确保有足够的数据...在这种情况下,我使用了if(bytes.length > 4096) ;)

你的解决方案成功加载了图片,但是未能确定它的实际尺寸。 - Pehat
你应该能够在loader.contentLoaderInfo的第一个完整事件上获取图片尺寸;) - Cay

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接