import flash.display.BitmapData; import flash.display.Bitmap; /** * 将图像的Alpha通道转换为黑白图像(分离ARGB方式) */ var bmpd:BitmapData = new ImagePNG();//绑定的png图片 var pixBmpd:BitmapData = new BitmapData(bmpd.width,bmpd.height,false); for (var i:int=0; i< bmpd.height; i++) { var s:String = ""; for (var j:int=0; j<bmpd.width; j++) { var pixel:uint = bmpd.getPixel32(j,i); var obj:Object = splitARGB(pixel); var temp:String = obj.a == 0 ? "00":obj.a.toString(16); s += temp + " "; pixel = mixRGB(obj.a); pixBmpd.setPixel(j,i,pixel); } //trace(s);//字符画 } var bmp:Bitmap = new Bitmap(pixBmpd); this.addChild(bmp); function splitARGB($argb:uint):Object { return {a:$argb >> 24 & 0xFF, r:$argb >> 16 & 0xFF, g:$argb >> 8 & 0xFF, b:$argb & 0xFF}; } function mixARGB($color:uint):uint { return $color << 24 | $color << 16 | $color << 8 | $color; } function mixRGB($color:uint):uint { return $color << 16 | $color << 8 | $color; }