开发者

Flash as3 smooth threshold

开发者 https://www.devze.com 2022-12-27 20:07 出处:网络
I\'m building a flash app that pulls images from flickr and removes the white background I\'m dong this using threshold and i get a really ragged outcome

I'm building a flash app that pulls images from flickr and removes the white background I'm dong this using threshold and i get a really ragged outcome is there any way to get a better and smoother color key? thanks photoNumber = Math.floor(Math.random() * (photos.length));

    loader.load(new URLRequest(photos[photoNumber].path));
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE,draw);
    trace ( "trying to load photo " + photoNumber );

    function draw(e:Event) {

    tra开发者_JS百科ce ("show photo " + photoNumber)

var W:int=e.target.content.width;
var H:int=e.target.content.height;

bitmapdata=new BitmapData(W,H);
bitmap=new Bitmap(bitmapdata);
bitmapdata.draw(e.target.content);

    var threshold:uint =  0xF9F8F800;
    var color:uint = 0x00000000;
    var maskColor:uint = 0x00FF0000;

bitmapdata.threshold(bitmapdata,new Rectangle(0,0,W,H),new Point(0,0),">", threshold, color, maskColor, true);

    bitmap.smoothing = true;
    //bitmap.scaleX = bitmap.scaleY = 0.99; // <----
    imgHolder.addChild(bitmap);

    }

}


Your mask and thresholds are not correct. I think you are trying to do something like this:

var threshold:uint =  0x00F9F8F8;
var maskColor:uint = 0x00FFFFFF;

The alpha is the first two hex chars.


If you only want to remove white pixels you can compare the image with a white bitmap in the same size and change the matching pixels (see: http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/BitmapData.html#compare%28%29).

0

精彩评论

暂无评论...
验证码 换一张
取 消