The purpose of the function is to covert the background to transparent and then return the bitmapdata, but it seems it do not work. The code is following:
private function transparentConverter( source:BitmapData, threshold:Number = 0.1 ):BitmapData
{
var bitmapData:BitmapData = new BitmapData( source.width, source.height, true, 0x00000000 );
bitmapData.lock();
var color:uint = source.getPixel( 0, 0 );
var x:uint, y:uint;
for ( y = 0; y < source.height; y++ )
{
for ( x = 0; x < source.width; x++ )
{
var c1:uint = source.getPixel( x, y );
var c2:uint = color;
var rx:uint = Math.abs((( c1 & 0xff0000 ) >> 16 ) - (( c2 & 0xff0000 ) >> 16 ));
var gx:uint = Math.abs((( c1 & 0xff00) >> 8 ) - (( c2 & 0xff00 ) >> 8 ));
var bx:uint = Math.abs(( c1 & 0xff ) - ( c2 & 0xff ));
var dist:uint = Math.sqrt( rx*rx + gx*gx + bx*bx );
if ( dist <= threshold )
{
bitmapData.setPixel32( x, y, 0x00000000 );
}else
{
bitmapData.setPixel32( x, y, c1 );
}
}
}
bitmapData.unlock();
return bitmapData;
}
Please advice.