画像処理 エッジ検出
// forked from ll_koba_ll's 白黒
// forked from ll_koba_ll's 2値化
// forked from ll_koba_ll's code on 2009-1-13
package
{
import flash.display.*;
import flash.events.*;
import flash.net.*;
import flash.system.*;
import flash.text.*;
import flash.geom.*;
import flash.filters.*;
[SWF(frameRate="30", backgroundColor="#000000")]
public class Edge extends Sprite
{
private var logoURL:String = "http://labs.un-q.net/wonderfl/images/pic.jpg"
private var proxyURL:String = "http://5ivestar.org/proxy/";
private var proxyCrossdomainURL:String = "http://5ivestar.org/proxy/crossdomain.xml";
private var loader:Loader;
private var _txt:TextField;
public function Edge()
{
addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event):void
{
stage.align = StageAlign.TOP_LEFT;
stage.quality = StageQuality.HIGH;
stage.scaleMode = StageScaleMode.NO_SCALE;
_txt = new TextField();
_txt.autoSize = TextFieldAutoSize.LEFT;
var _tf:TextFormat = new TextFormat();
_tf.font = "_ゴシック";
_tf.size = 14;
_tf.color = 0xFFFFFF;
_txt.defaultTextFormat = _tf;
_txt.appendText("画像読み込み中...");
addChild(_txt);
Security.loadPolicyFile(proxyCrossdomainURL);
loader = new Loader();
loader.load(new URLRequest(proxyURL+logoURL));
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadCompleteHandler);
}
private function loadCompleteHandler(e:Event):void
{
removeChild(_txt);
var p:Point = new Point();
var mtx:Matrix = new Matrix();
mtx.scale(2,2);
var s:BitmapData = new BitmapData(loader.width*2, loader.height*2, true, 0xFFFFFFFF);
s.draw(loader, mtx);
var a:Array = [1,1,1,1,1,-8,1,1,1,1];
s.applyFilter(s, s.rect, p, new ConvolutionFilter(3, 3, a));
var disp:DisplayObject = addChild(new Bitmap(s)) as DisplayObject;
disp.x = stage.stageWidth/2 - disp.width/2;
disp.y = stage.stageHeight/2 - disp.height/2;
}
}
}