In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

画像処理 2値化

Get Adobe Flash player
by ll_koba_ll 10 Feb 2009
// 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 frocessing.color.*;
    
    [SWF(frameRate="30", backgroundColor="#000000")]
    public class LineSketch01 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 LineSketch01()
        {
            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 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 d:BitmapData = new BitmapData(s.width, s.height, true, 0xFFFFFFFF);
            d.fillRect(s.rect, 0xFFFFFFFF);
            d.threshold(s, s.rect, new Point(), "<=",128 , 0xFFFF00, 255, false);
            
            var disp:DisplayObject = addChild(new Bitmap(d)) as DisplayObject;
            
            disp.x = stage.stageWidth/2 - disp.width/2;
            disp.y = stage.stageHeight/2 - disp.height/2;            
        }
    }
}