你如何加载位图文件到BitmapData对象?位图、加载、对象、文件

2023-09-08 11:02:49 作者:执念致伤成痛

在闪存中,的BitmapData 对象可以用来存储在RAM中的位图,则可以在以后使用它们画到MovieClip的 beginBitmapFill()方法。

In Flash, the BitmapData object can be used to store bitmaps in RAM, you can later draw them to a MovieClip using the beginBitmapFill() method.

你如何加载外部的位图文件(.JPG)到BitmapData对象?

How do you load an external bitmap file (.jpg) into a BitmapData object?

即使AS3 code将是有益的。

Even AS3 code would be helpful.

推荐答案

AS3 code加载PNG和搞定它的位图数据。

AS3 code to load a PNG and "get" its bitmapData

var bitmapData:BitmapData;

var loader:Loader = new Loader();
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
    loader.load(new URLRequest("../lib/img.png"));

function onComplete (event:Event):void
{
    bitmapData = Bitmap(LoaderInfo(event.target).content).bitmapData;
}