问题描述
我想问一件事:
如果我创建Loader和加载方URLRequest外部形象,生病了结果:
If i create Loader and load external image by URLRequest , ill have result :
loader.content is Bitmap
loader.content.bitmapData is BitmapData
但是,如果我使用Loader.loadBytes(ImageBytes),结果是不同的,即使ImageBytes是loader.contentLoaderInfo.bytes:
But if I use Loader.loadBytes(ImageBytes) , result is different even if ImageBytes is loader.contentLoaderInfo.bytes :
bytesLoader.content is MovieClip
bytesLoader.content.getChildAt(0) is Bitmap
bytesLoader.content.getChildAt(0).bitmapData is BitmapData
为什么?
推荐答案
AS3 Loader具有内部解析尝试和匹配数据类型的内部类类型。这是pretty的方便,在大多数情况下,但语法是有点怪异。
AS3 Loader has internal parsing to try and match datatypes to internal class types. It's pretty handy in most cases, but the syntax is a little weird.
在上面的例子中,你可以投bytesLoader.content为位图,如果您愿意。
In your example above, you CAN cast the bytesLoader.content as Bitmap if you'd rather.
编辑(参考如何的问题):
Edit (in reference to the "how" question):
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, getImage);
ldr.load ( new URLRequest ( IMAGE_URL ) );
function getImage (e:Event):void {
var bmp:Bitmap = ldr.content as Bitmap;
addChild (bmp);
}
您应该可以简单地把它作为一个位图。
You should be able to simply cast it as a Bitmap.
这篇关于通过Loader.loadBytes加载图像(字节阵列)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!