Import image as BitmapData


(Joseph Sweeney) #1

I like to use .png files to store map data when I’m designing levels. To get at the data, I typically do something like this:

var img:Image = new Image(Art.MAP);
var data:BitmapData = new BitmapData(img.width, img.height, true, 0x00000000);
img.render(data, new Point, new Point);

Where Art.MAP is a .png image embedded in the Art class.

I’m wondering if there is a simpler way to import the .png as a BitmapData.


(Jacob Albano) #2

Art.MAP already represents a BitmapData asset, actually.
[EDIT] Wrong, see comment below.

var data:BitmapData = new Art.MAP;

(Joseph Sweeney) #3

Ah, thanks! I figured it was something as simple as that.


(Joseph Sweeney) #4

Hm. trying it out doesn’t seem to work. Casting is also producing an error.


(Jacob Albano) #5

Sorry, I was wrong: embedded assets are Bitmaps, not BitmapDatas.

var data:BitmapData = Bitmap(new Art.MAP).bitmapData;

(Joseph Sweeney) #6

Great! Works perfectly.


(JP Mortiboys) #7

FP has bitmap caching built-in - why not just do

var data:BitmapData = FP.getBitmap(Art.MAP);

(Joseph Sweeney) #8

You know, I think I’ve actually seen/used that before but just forgot it was there! Thanks for the reminder.