views:

39

answers:

1

I have a Sprite which is in the shape of a Convex polygon(not rectangular).
If I take its snapshot using :

var bmd:BitmapData = new BitmapData(width,height);  
bmd.draw(someSprite,someMatrix,null,null,null);

I get an image like this :

Click here to see the image

In this image, I have added the green boundary myself, just to show
the dimensions of the image.

So, when I took a snapshot of the convex polygon shaped sprite
using draw method of the BitmapData class, I got a red triangle
with a white ellipse inside and for rest of the area, I got while pixels.

I want to replace those outer white pixels with blue colored pixels.

How do I do it?

A: 

You could use the BitmapData.floodFill() method. It works just like the "paint bucket tool".

All that is left is finding a pixel inside the white area you want to replace. For instance, if you are certain that there will always exist a white border around the sprite, you can assume the top-left pixel is a perfect spot. Doing so would then solve the problem:

bmd.floodFill(0, 0, 0xff0000ff); //note that the color is in ARGB format.

If you can't assume that, the problem is not about filling the white area, but finding it. We'd need to know more about your problem then. We couldn't just loop through the borders looking for white pixels as those could be actually the middle ellipse, for example.

MrKishi
I was assuming there were actually white pixels in the outer area. Now that I re-read your question title, I must ask: are those really white or are they just transparent pixels? If they are transparent and the sprite is solid, it'd be easier. You just need to create the BitmapData with a blue background.
MrKishi
both of them didn't work for me. may be I am doing something wrong.
dta