user1325532
user1325532

Reputation: 61

how to fill solid color into the shape of a transparent PNG file with actionscript3?

For example, I have a transparent png file, the shape is a car. In the png file, I only draw the white border shape. Outside and inside the border are all transparent.

I want to use actionscript3 code to show the car object with different color, it means only fill color inside the border, and for the outside of the border, keep transparent. How to do that?

So far, the simplest workaround is to prepare many images with PhotoShop, but it's not good enough for me. When I have many shapes and use many colors, I've to prepare many many images.

Add more details: (Because I'm using white border, you may not see the basic png file if your background of browser is white) This is my basic png file

this is my expected car 1

this is my expected car 2

Change my boarder of shape to black, hope this is helpful to understand my question.

enter image description here

enter image description here

enter image description here

Upvotes: 2

Views: 3656

Answers (2)

George Profenza
George Profenza

Reputation: 51837

Since you're working with loaded images/pixels you can make use of BitmapData's floodFill() which pretty much does what you need. There's an example in bellow the method description as well.

It does pretty much what you need, although in some cases it might not be perfect. It's worth having a look at Jan's optimizing the floodFill() method article which goes more in depth.

advanced floodFill() example

Upvotes: 2

Luke Van In
Luke Van In

Reputation: 5265

A simple solution is to use multiple layers. The top layer would contain just the border. The lower layer would contain just the car with no border. You can adjust the colour of the car layer using a ColorTransform or ColorMatrixFilter.

Upvotes: 0

Related Questions