ActionScript 3.0 語法:
//引入函式庫
import flash.utils.ByteArray;
import flash.display.BitmapData;
import PNGEncoder;
//輸出圖片寬
var saveWidth:uint = 600;
//輸出圖片高
var saveHeight:uint = 500;
//建立透明點陣圖影像
var _bitmapData:BitmapData=new BitmapData(saveWidth, saveHeight, true, 0xFFFFFF);
//設定影像位移
var myMatrix:Matrix = new Matrix();
var tx:Number=-33;
var ty:Number=-40;
myMatrix.translate(tx, ty);
//將畫面描繪至點陣圖
_bitmapData.draw(stage,myMatrix);
//將黑色取代為透明色
for (var i=1; i<=saveWidth; i++){
 for (var j=1; j<=saveHeight; j++){
  if (_bitmapData.getPixel32(i, j).toString(16)=='ff000000'){
   _bitmapData.setPixel32(i, j, 0x00FFFFFF);
  }
 }
}
//將BitmapData編碼成ByteArray格式
var _byte:ByteArray=PNGEncoder.encode(_bitmapData);
//輸出點陣圖
var _file2:FileReference = new FileReference();
_file2.save(_byte ,"test.png");

1 意見:
這樣只要是黑色的都不見了。。太神奇了。。
張貼留言