如何动态地加载一个渐进JPEG / JPG使用actionscrip-3的Flash并知道它的宽度/高度之前完全加载加载、它的、宽度、高度

2023-09-08 12:30:06 作者:重度孤独患者

我试图动态加载使用ActionScript 3这样做一个渐进式JPEG,我创建了一个名为Progressiveloader创建一个URLStream并用它来Streamload公司的渐进式JPEG字节到ByteArray。每次的ByteArray的增长,我使用Loader来loadBytes从ByteArray。这工作,在一定程度上,因为如果我的addChild装载程序,我能看到JPEG,因为它是流,但我无法访问装载程序的内容,最重要的是,我不能改变装载的宽度和高度

I am trying to dynamically load a progressive jpeg using actionscript 3. To do so, I have created a class called Progressiveloader that creates a URLStream and uses it to streamload the progressive jpeg bytes into a byteArray. Everytime the byteArray grows, I use a Loader to loadBytes the byteArray. This works, to some extent, because if I addChild the Loader, I am able to see the jpeg as it is streamed, but I am unable to access the Loader's content and most importantly, I can not change the width and height of the Loader.

大量的测试之后,我似乎已经找到了问题的原因是,直到装载机已经完全加载的JPG格式,这意味着直到他实际看到的JPG格式的结束字节,他不知道的宽度和身高和他不创建内容的DisplayObject与装载机的内容相关联。

After a lot of testing, I seem to have figured out the cause of the problem is that until the Loader has completely loaded the jpg, meaning until he actually sees the end byte of the jpg, he does not know the width and height and he does not create a content DisplayObject to be associated with the Loader's content.

我的问题是,会不会有被加载之前,有一种方法可以真正了解JPEG的宽度和高度?

My question is, would there be a way to actually know the width and height of the jpeg before it is loaded?

PS:我认为这是可能的,一个渐进式JPEG的性质,因为,它被加载到它的全尺寸,但细节较少,所以尺寸应该知道。装载在这样一个正常的jpeg即使当,尺寸屏幕上看到,除了其还没有加载的像素表示为灰色。

P.S.: I would believe this would be possible, because of the nature of a progressive jpeg, it is loaded to it's full size, but with less detail, so size should be known. Even when loading a normal jpeg in this way, the size is seen on screen, except the pixels which are not loaded yet are showing as gray.

感谢你。

推荐答案

我觉得你的问题是,loadBytes是asyncronous ......这意味着,你需要等待,直到你恢复(或改变)之前的完成事件的宽度和高度......我的意思是:

I think your problem is that loadBytes is asyncronous... that means that you need to wait until the "complete" event before you retrieve (or change) its width and height... I mean:

var loader:Loader=new Loader();
loader.loadBytes(myBytes);
trace(loader.width, loader.contentLoaderInfo.width); //will always output zero
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imgLoaded);
function imgLoaded(e) {
   trace(loader.width, loader.height); //will output the loader dimensions
   trace(loader.contentLoaderInfo.width, loader.contentLoaderInfo.height); //will always output the original JPEG dimensions
}