Reputation: 39
I want to get the color from the movieclip. I am Using Following Code:
for (var j = 0; j <bmpd.width; j++)
{
for (var k = 0; k <bmpd.height; k++)
{
trace("0x"+bmpd.getPixel(j,k).toString(16))
}
}
Here Circle is a MovieClip.please guide me
Upvotes: 1
Views: 1852
Reputation: 12420
You have to extract the color channels:
for (var j = 0; j < bmpd.width; j++) {
for (var k = 0; k < bmpd.height; k++) {
// Read the pixel color
var color:uint = bmpd.getPixel(j, k);
// Read color channel values
var alpha:uint = color >> 24 & 0xFF;
var red:uint = color >> 16 & 0xFF;
var green:uint = color >> 8 & 0xFF;
var blue:uint = color & 0xFF;
// Reassemble the color
trace("color: 0x" + red.toString(16) + green.toString(16) + blue.toString(16));
trace("alpha: 0x" + alpha.toString(16));
}
}
Upvotes: 2
Reputation: 18747
To get a color on your MovieClip at a certain point or range, you should create a transparent BitmapData of required capacity (1x1 for point), fill it with 0x0 color, then create a transform matrix aligning (0,0) of BitmapData to upper left corner of your region, then draw that MC on the bitmap, then you can query its pixels. An example (a point):
private static var hitTestBD:BitmapData=new BitmapData(1,1,true,0);
private static vat hitTestMatrix:Matrix=new Matrix();
public static function getMCColor(mc:DisplayObject,tx:Number,ty:Number):uint {
hitTestMatrix.identity();
hitTestMatrix.translate(-1*tx,-1*ty); // aligning
hitTestBD.fillRect(hitTestBD.rect,0x0);
hitTestBD.draw(mc,hitTestMatrix);
return hitTestBD.getPixel32(0,0);
}
Upvotes: 3