Created
September 18, 2009 11:22
-
-
Save youpy/189012 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // forked from llcheesell's webcam | |
| package { | |
| import flash.display.Sprite; | |
| import flash.display.Bitmap; | |
| import flash.display.BitmapData; | |
| import flash.events.*; | |
| import flash.media.Camera; | |
| import flash.media.Video; | |
| import flash.utils.ByteArray; | |
| import flash.geom.Rectangle; | |
| public class CameraView extends Sprite { | |
| private var video:Video; | |
| private var cameraBmp:Bitmap; | |
| private var cameraBmpData:BitmapData; | |
| private var w:int = 320; | |
| private var h:int = 240; | |
| public function CameraView() { | |
| var camera:Camera = Camera.getCamera(); | |
| if (camera != null) { | |
| video = new Video(w, h); | |
| video.attachCamera(camera); | |
| addEventListener(Event.ENTER_FRAME, tick); | |
| } else { | |
| trace("error"); | |
| } | |
| cameraBmpData = new BitmapData(w, h, false, 0xaaaaaa); | |
| cameraBmp = new Bitmap(cameraBmpData); | |
| addChild(cameraBmp); | |
| //root.stage.frameRate = 5; | |
| } | |
| private function tick(event:Event):void { | |
| if(video == null) { | |
| return; | |
| } | |
| var pixels:Array = []; | |
| var x:int, y:int; | |
| cameraBmpData.draw(video); | |
| for(x = 0; x < w; x ++) { | |
| for(y = 0; y < h; y ++) { | |
| pixels.push(cameraBmpData.getPixel(x, y)); | |
| } | |
| } | |
| pixels = pixels.sort(Array.NUMERIC); | |
| var i:int = 0; | |
| for(x = 0; x < w; x ++) { | |
| for(y = 0; y < h; y ++) { | |
| cameraBmpData.setPixel(x, y, pixels[i++]); | |
| } | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment