loading image by Loader.loadBytes(byteArray)

*爱你&永不变心* 提交于 2019-12-02 17:51:08

问题


i like to ask about one thing :

If i create Loader and load external image by URLRequest , ill have result :

loader.content is Bitmap
loader.content.bitmapData is BitmapData

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

why ?


回答1:


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.

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.



来源:https://stackoverflow.com/questions/8110803/loading-image-by-loader-loadbytesbytearray

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!