2010年12月11日 星期六

[AS3] BitmapData.copyChannel()方法(一) - 挑選自身或其它BitmapData物件的某色版,傳送到目標色版

copyChannel()方法
public function copyChannel(sourceBitmapData:BitmapData, sourceRect:Rectangle, destPoint:Point, sourceChannel:uint, destChannel:uint):void


991211_BitmapData.copyChannel_1.swf - 未使用copyChannel()方法,載入991211_photo_1.jpg圖檔




import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.display.BitmapData;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.geom.Rectangle;
import flash.geom.Point;
import flash.display.Bitmap;

//
const bmURL:String = "991211_photo_1.jpg";
var ldr:Loader = new Loader();
ldr.load(new URLRequest(bmURL));
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaderComplete);
ldr.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgress);

//
var bmData1:BitmapData;
//var bmData2:BitmapData;
var bm1:Bitmap;
//var bm2:Bitmap;
//
var format:TextFormat = new TextFormat();
with(format){
 color = 0xff00ff;
 size = 88;
 font = "Lucida Fax";
 bold = true;
 align = "center";
}
//
var tF:TextField = new TextField;
with(tF){
 x = 0;
 y = 150;
 width = 550;
 //autoSize = TextFieldAutoSize.LEFT;
}
tF.defaultTextFormat = format;
addChild(tF);

//
function onProgress(e:ProgressEvent):void{
 tF.text = String(Math.floor((e.bytesLoaded/e.bytesTotal*100)));
}

//
var rect:Rectangle = new Rectangle(0,0, 550, 400);
var point:Point = new Point(0, 0);
//
function onLoaderComplete(e:Event):void{
 gogo();
}
//
function gogo(){
 bmData1 = (ldr.content as Bitmap).bitmapData;
 //bmData1.copyChannel(bmData1, rect, point, BitmapDataChannel.BLUE, BitmapDataChannel.RED);
 bm1 = new Bitmap(bmData1);
 addChild(bm1);
}




991211_BitmapData.copyChannel_1a.swf - 使用copyChannel()方法,載入991211_photo_1.jpg圖檔
→ copyChannel(bmData1, rect, point, BitmapDataChannel.BLUE, BitmapDataChannel.RED);




import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.display.BitmapData;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.geom.Rectangle;
import flash.geom.Point;
import flash.display.Bitmap;

//
const bmURL:String = "991211_photo_1.jpg";
var ldr:Loader = new Loader();
ldr.load(new URLRequest(bmURL));
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaderComplete);
ldr.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgress);

//
var bmData1:BitmapData;
var bmData2:BitmapData;
var bm1:Bitmap;
var bm2:Bitmap;
//
var format:TextFormat = new TextFormat();
with(format){
 color = 0xff00ff;
 size = 88;
 font = "Lucida Fax";
 bold = true;
 align = "center";
}
//
var tF:TextField = new TextField;
with(tF){
 x = 0;
 y = 150;
 width = 550;
 //autoSize = TextFieldAutoSize.LEFT;
}
tF.defaultTextFormat = format;
addChild(tF);

//
function onProgress(e:ProgressEvent):void{
 tF.text = String(Math.floor((e.bytesLoaded/e.bytesTotal*100)));
}

//
var rect:Rectangle = new Rectangle(0,0, 550, 400);
var point:Point = new Point(0, 0);
//
function onLoaderComplete(e:Event):void{
 gogo();
}
//
function gogo(){
 bmData1 = (ldr.content as Bitmap).bitmapData;
 bmData1.copyChannel(bmData1, rect, point, BitmapDataChannel.BLUE, BitmapDataChannel.RED);
 bm1 = new Bitmap(bmData1);
 addChild(bm1);
}




991211_BitmapData.copyChannel_1b.swf - 使用copyChannel()方法,載入991211_photo_1.jpg圖檔
→ bmData1.copyChannel(bmData1, rect, point, BitmapDataChannel.RED, BitmapDataChannel.BLUE);




import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.display.BitmapData;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.geom.Rectangle;
import flash.geom.Point;
import flash.display.Bitmap;

//
const bmURL:String = "991211_photo_1.jpg";
var ldr:Loader = new Loader();
ldr.load(new URLRequest(bmURL));
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaderComplete);
ldr.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgress);

//
var bmData1:BitmapData;
var bmData2:BitmapData;
var bm1:Bitmap;
var bm2:Bitmap;
//
var format:TextFormat = new TextFormat();
with(format){
 color = 0xff00ff;
 size = 88;
 font = "Lucida Fax";
 bold = true;
 align = "center";
}
//
var tF:TextField = new TextField;
with(tF){
 x = 0;
 y = 150;
 width = 550;
 //autoSize = TextFieldAutoSize.LEFT;
}
tF.defaultTextFormat = format;
addChild(tF);

//
function onProgress(e:ProgressEvent):void{
 tF.text = String(Math.floor((e.bytesLoaded/e.bytesTotal*100)));
}

//
var rect:Rectangle = new Rectangle(0,0, 600, 450);
var point:Point = new Point(-50, -50);
//
function onLoaderComplete(e:Event):void{
 gogo();
}
//
function gogo(){
 bmData1 = (ldr.content as Bitmap).bitmapData;
 bmData1.copyChannel(bmData1, rect, point, BitmapDataChannel.RED, BitmapDataChannel.BLUE);
 bm1 = new Bitmap(bmData1);
 addChild(bm1);
}




參閱適用於 Adobe Flash Professional CS5 的 ActionScript 3.0 參考 - Flash Help關於BitmapData.copyChannel()的資訊

沒有留言: