PDA

View Full Version : getting x y value from a bitmap image.


deluxmilkman
02-28-2008, 08:48 AM
hi,
i have a bitmap(black and green), and
i would like to get x and y values of the top left conner of the green area(See atached jpg). is this possible with as?

lordofduct
02-28-2008, 09:26 AM
yeah it is possible... you have a few options I can think of off the top of my head (though I may be mixing some of the methods up in my head with other languages).

Anyways... lots of stuff that could go over for that so I'll link you to here:
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/BitmapData.html

First you can't just get it from the Bitmap (I assume you know this if you've edited your Bitmap to the green and black image). Anyways get the BitmapData from the Bitmap and you can use a multitude of methods to pull out per pixel information.

BitmapData has a nice method available BitmapData.getColorBoundsRect... with this you pass in a mask that contains the color you are looking for in the Bitmap and returns a rectangle with size and position in the image of a region that contains all pixels of that color.

Downside is it considers an entire image and if the image contains multiple areas of that color you'll probably get a very large rectangle. But in the case of your supplied image it should return a rectangle around what looks like a marker.

Maybe you should try transforming the color to make the black more prominent and clean out any noise that might turn up green and alter your rectangle result.

deluxmilkman
02-29-2008, 12:28 AM
thanks. getColorBoundsRect is great.

lordofduct
02-29-2008, 02:07 AM
you should probably save a link to this page here:
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/index.html?appendixes.html&all-classes.html

I always go there when I start getting stumped on ways to deal with things. It's like digging through the box of legos looking for that one weird piece that just might help.