I used BitmapData class to get pixel from an image
Here is the code :
package {
//
import flash.display.BitmapData;
import flash.geom.ColorTransform;
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.MouseEvent;
//
public class RePainting extends Sprite {
//
private var _bmp:BitmapData;
private var _con:MovieClip;
private var _cf:ColorTransform;
private var _dot:Dot;
private var _plus:int;
private var _xc:int;
private var _yc:int;
private var _tw:Number;
private var _th:Number;
private var _t:Timer;
//
public function RePainting():void {
//
_init();
}
//
private function _init():void {
_bmp = new BitmapData(img_mc.width, img_mc.height);
_con = new MovieClip();
_cf = new ColorTransform();
_plus = 5;
_xc = 0;
_yc = 0;
_tw = img_mc.width;
_th = img_mc.height;
_t = new Timer(1);
//
this.addChild(_con);
_bmp.draw(img_mc);
_t.addEventListener(TimerEvent.TIMER, _drawIMG);
_t.start();
}
//
private function _drawIMG(event:TimerEvent):void {
//
_dot = new Dot();
_cf = _dot.transform.colorTransform;
_cf.color = _bmp.getPixel(_xc, _yc);
_dot.transform.colorTransform = _cf;
_con.addChild(_dot);
_dot.x = _xc / _plus * _dot.width;
_dot.y = _yc / _plus * _dot.height;
//
if(_xc >= _tw && _yc >= _th) {
_clearIMG();
}else if(_xc >= _tw) {
_xc = (-1) * _plus;
_yc += _plus;
}
_xc += _plus;
}
//
private function _clearIMG() {
//this.removeChild(_con);
_t.stop();
}
}
}
- Sep 19 Wed 2007 00:44
BitmapData practice 1
close
全站熱搜
留言列表