开发者

Programmatically load images in Flex

开发者 https://www.devze.com 2022-12-13 06:54 出处:网络
I need to load several images as Bitmap or BitmapData objects. The images are hosted outside the Flex project, and they\'re referenced by an extern开发者_StackOverflow中文版al configuration file, so I

I need to load several images as Bitmap or BitmapData objects. The images are hosted outside the Flex project, and they're referenced by an extern开发者_StackOverflow中文版al configuration file, so I can't embed them. Because the images won't be displayed directly to the user (they're being added to a PDF that is generated for download), creating a grouping of Image objects, attaching them to the application, and waiting for their LoadComplete handler to fire seems inefficient.

What is the best way to load these images into an application?


Have you considered using Loader class?

var ldr:Loader = new Loader();
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoad);
ldr.load(new URLRequest("image.png"));

function onLoad(e:Event):void
{
    var image:Bitmap = Bitmap(LoaderInfo(e.target).content);
    var bmpData:BitmapData = image.bitmapData;
    //use bmpdata the way you want
    trace(bmpdata.width);
    trace(bmpdata.height);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号