package {
import flash.display.*; import flash.events.*; import flash.ui.Mouse; import flash.net.*; public class TurnGray extends Sprite { private var myURL:String = "images_01.jpg"; private var originalBitmapData:BitmapData; private var squareBitmapData:BitmapData; private var grayBitmapData:BitmapData; private var loaded:Boolean = false; private var loader:Loader; private var pic:Bitmap; private var color:uint; private var gray:uint; private var R:uint; private var squareLength:int = 30; private var xMouse:Number; private var yMouse:Number; public function TurnGray():void { download(); stage.addEventListener(MouseEvent.MOUSE_MOVE,onMousemove); function onMousemove(e:MouseEvent):void { bitmapDataGray(); e.updateAfterEvent(); } } public function download():void { loader = new Loader(); loader.load(new URLRequest(myURL)); loader.contentLoaderInfo.addEventListener(Event.INIT,onLoaded); function onLoaded(e:Event):void { loaded = true; originalBitmapData = Bitmap(e.target.content).bitmapData; pic = new Bitmap(originalBitmapData); addChild(pic); } } private function bitmapDataGray():void { var xMouse = mouseX; var yMouse = mouseY; for (var i:int = (xMouse-squareLength/2); i<(xMouse+squareLength/2); i++) { for (var j:int = (yMouse-squareLength/2); j<(yMouse+squareLength/2); j++) { color = originalBitmapData.getPixel(i,j); R = (color>>16) & (0xff); gray = R + (R<<8)+(R<<16); originalBitmapData.setPixel(i,j,gray); } } } } } |
Word教程网 | Excel教程网 | Dreamweaver教程网 | Fireworks教程网 | PPT教程网 | FLASH教程网 | PS教程网 |
HTML教程网 | DIV CSS教程网 | FLASH AS教程网 | ACCESS教程网 | SQL SERVER教程网 | C语言教程网 | JAVASCRIPT教程网 |
ASP教程网 | ASP.NET教程网 | CorelDraw教程网 |