Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you load a bitmap file into a BitmapData object?

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.

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

Even AS3 code would be helpful.

like image 624
Robin Rodricks Avatar asked Mar 31 '09 17:03

Robin Rodricks


4 Answers

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;
}
like image 90
Cotton Avatar answered Nov 19 '22 00:11

Cotton


Refering to the first post by cotton.

Actually each image is a bitmap so all you need to do is

bitmapData = event.target.content.bitmapData  

instead of

bitmapData = Bitmap(LoaderInfo(event.target).content).bitmapData;
like image 41
will Avatar answered Nov 19 '22 01:11

will


taking from cotton and will, this will display the bitmap after it is loaded:

import flash.display.Bitmap;
import flash.display.BitmapData;

var bitmapData:BitmapData;
var bmVis:Bitmap;

var loader:Loader = new Loader();
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
    loader.load(new URLRequest("put url here"));

function onComplete (event:Event):void
{
    trace("loaded!");
    bitmapData = event.target.content.bitmapData;
    bmVis = new Bitmap(bitmapData);
    this.addChild(bmVis);
}
like image 6
John Mark Isaac Madison Avatar answered Nov 19 '22 01:11

John Mark Isaac Madison


You have to load the external file (.jpg) into a MovieClip and wait for it to load.

Then take a snapshot of the MovieClip that contains the external file, into your BitmapData object.

myBitmap = new BitmapData(myMC._width, myMC._height,true,0x00FFFFFF)

myBitmap.draw( myMC)

See Introducing the Image API in Flash 8.

like image 5
Robin Rodricks Avatar answered Nov 19 '22 01:11

Robin Rodricks