daily pastebin goal
5%
SHARE
TWEET

Untitled

a guest Apr 16th, 2018 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package {
  2.   import flash.media.Sound;
  3.   import flash.media.SoundChannel;
  4.   import flash.events.Event;
  5.   import flash.events.SampleDataEvent;
  6.   import flash.display.Sprite;
  7.   import flash.display.Bitmap;
  8.   import flash.display.BitmapData;
  9.   import flash.events.*;
  10.   import flash.media.Camera;
  11.   import flash.media.Video;
  12.   import flash.utils.ByteArray;
  13.  
  14.   public class CameraView extends Sprite {
  15.     private var video:Video;
  16.     private var cameraBmp:Bitmap;
  17.     private var cameraBmpData:BitmapData;
  18.     private var w:int = 100;
  19.     private var h:int = 80;
  20.     private var mySound:Sound = new Sound();
  21.     private var myChannel:SoundChannel;
  22.  
  23.     public function CameraView() {
  24.       var camera:Camera = Camera.getCamera();
  25.  
  26.       if (camera != null) {
  27.         video = new Video(w, h);
  28.         video.attachCamera(camera);
  29.  
  30.         addEventListener(Event.ENTER_FRAME, tick);
  31.       } else {
  32.         trace("error");
  33.       }
  34.  
  35.       cameraBmpData = new BitmapData(w, h, false, 0xaaaaaa);
  36.       cameraBmp = new Bitmap(cameraBmpData);
  37.       addChild(cameraBmp);
  38.      
  39.       mySound.addEventListener(SampleDataEvent.SAMPLE_DATA, onSampleData);
  40.       myChannel = mySound.play();
  41.     }
  42.  
  43.     private function tick(event:Event):void {
  44.       cameraBmpData.draw(video);
  45.     }
  46.  
  47.     private function onSampleData(e:SampleDataEvent):void {
  48.       var r:Number, g:Number;
  49.  
  50.       for (var i:int = 0; i < h; i++) {
  51.         for (var j:int = 0; j < w; j++) {
  52.           r = ((cameraBmpData.getPixel(j, i) >> 16) / 128.0) - 1;
  53.           g = ((cameraBmpData.getPixel(j, i) >> 8 & 0x0000ff) / 128.0) - 1;
  54.          
  55.           e.data.writeFloat(r);
  56.           e.data.writeFloat(g);
  57.         }
  58.       }
  59.     }
  60.   }
  61. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top