AA cam
package
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.events.Event;
import flash.filters.ColorMatrixFilter;
import flash.geom.Rectangle;
import flash.media.Camera;
import flash.media.Video;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;
import flash.utils.ByteArray;
[SWF(width="465", height="465", backgroundColor="0xffffff", frameRate="30")]
public class TestCam extends Sprite
{
private var cam:Camera;
private var vid:Video;
private var pw:int = 48;
private var ph:int = 36;
private var txt:TextField;
private var bmd:BitmapData;
private var ascii:Array = ["冊", "田", "五", "ヨ", "三", "二", "一", " "];
private var tf:TextFormat = new TextFormat("MS ゴシック", 8, 0, false, false, false, null, null, TextFormatAlign.LEFT, 0, 0, 0, 0);
public function TestCam() {
cam = Camera.getCamera();
cam.setMode(pw*10, ph*10, 30);
vid = new Video(pw, ph);
vid.attachCamera(cam);
vid.filters = [new ColorMatrixFilter([
// 赤:0.29891 緑:0.58661 青:0.11448)
0.29891, 0.58661, 0.11448, 0, 0,
0.29891, 0.58661, 0.11448, 0, 0,
0.29891, 0.58661, 0.11448, 0, 0,
0,0,0,1,0
])];
bmd = new BitmapData(pw, ph);
txt = new TextField();
txt.autoSize = TextFieldAutoSize.LEFT;
txt.text = "";
addChild(txt);
addEventListener(Event.ENTER_FRAME, loop);
}
private function loop(e:Event):void {
bmd.draw(vid);
var bts:ByteArray = bmd.getPixels(new Rectangle(0, 0, pw, ph));
bts.position = 0;
//txt.text = "";
var str:String = "";
var c :int;
for (var i:int = 0; i < ph; i++)
{
for (var j:int = 0; j < pw; j++)
{
c = bts.readUnsignedInt();
c &= 0xff;
c >>>= 5;
//txt.appendText(ascii[c]);
str += ascii[c];
}
//txt.appendText("\n");
str += "\n";
}
txt.text = str;
txt.setTextFormat(tf);
}
}
}