Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package {
- import com.pfp.events.JPEGAsyncCompleteEvent;
- import com.pfp.utils.JPEGAsyncEncoder;
- import flash.display.Bitmap;
- import flash.display.BitmapData;
- import flash.display.Sprite;
- import flash.display.StageAlign;
- import flash.display.StageScaleMode;
- import flash.events.MouseEvent;
- import flash.filesystem.File;
- import flash.filesystem.FileMode;
- import flash.filesystem.FileStream;
- import flash.media.Camera;
- import flash.media.Video;
- import flash.utils.ByteArray;
- import qnx.dialog.AlertDialog;
- import qnx.ui.buttons.LabelButton;
- import qnx.ui.text.TextInput;
- public class fishyLightningCam extends Sprite {
- private var bitmapData:BitmapData = new BitmapData(972, 546);
- private var bitmap:Bitmap;
- private var byteArray:ByteArray;
- private var file:File = File.documentsDirectory;
- private var fstream:FileStream;
- private var captureBTN:LabelButton = new LabelButton();
- private var discardBTN:LabelButton = new LabelButton();
- private var saveBTN:LabelButton = new LabelButton();
- private var fileName:TextInput = new TextInput();
- private var cam:Camera = Camera.getCamera("1");
- private var vid:Video = new Video(972, 546);
- private var jpgEncoder:JPEGAsyncEncoder;
- public function fishyLightningCam() {
- super();
- // support autoOrients
- stage.align = StageAlign.TOP_LEFT;
- stage.scaleMode = StageScaleMode.NO_SCALE;
- cam.setMode(2592, 1456, 30, true);
- cam.setQuality(0, 100);
- takePictures();
- }
- private function takePictures():void {
- if (cam != null) {
- vid.attachCamera(cam);
- vid.x = 26;
- vid.y = 5;
- addChild(vid);
- } else {
- var noCamAlert:AlertDialog = new AlertDialog();
- noCamAlert.title = "Camera Error";
- noCamAlert.message = "No camera was detected. Please ensure no other apps are using the camera.";
- noCamAlert.addButton("Okay");
- noCamAlert.show();
- }
- captureBTN.label = "Capture!";
- captureBTN.setPosition(400, 550);
- captureBTN.width = 224;
- captureBTN.addEventListener(MouseEvent.CLICK, captureImage);
- addChild(captureBTN);
- fileName.prompt = "File Name";
- fileName.setPosition(36, 555);
- fileName.width = 350;
- fileName.visible = false;
- addChild(fileName);
- saveBTN.label = "Save";
- saveBTN.setPosition(400, 550);
- saveBTN.width = 100;
- saveBTN.visible = false;
- saveBTN.addEventListener(MouseEvent.CLICK, saveCapture);
- addChild(saveBTN);
- discardBTN.label = "Discard";
- discardBTN.setPosition(524, 550);
- discardBTN.width = 100;
- discardBTN.visible = false;
- discardBTN.addEventListener(MouseEvent.CLICK, discardCapture);
- addChild(discardBTN);
- }
- private function captureImage(e:MouseEvent):void {
- bitmapData.draw(vid);
- bitmap = new Bitmap(bitmapData);
- bitmap.x = 26;
- bitmap.y = 5;
- addChild(bitmap);
- removeChild(vid);
- captureBTN.visible = false;
- saveBTN.visible = true;
- discardBTN.visible = true;
- fileName.visible = true;
- }
- private function saveCapture(e:MouseEvent):void {
- jpgEncoder = new JPEGAsyncEncoder(100);
- jpgEncoder.addEventListener(JPEGAsyncCompleteEvent.JPEGASYNC_COMPLETE, encodeWIN);
- jpgEncoder.encode(bitmapData);
- }
- private function encodeWIN(e:JPEGAsyncCompleteEvent):void {
- addChild(vid);
- removeChild(bitmap);
- fstream = new FileStream();
- fstream.openAsync(file.resolvePath(fileName.text + ".jpg"), FileMode.WRITE);
- fstream.writeBytes(e.ImageData);
- /* byteArray = new ByteArray();
- byteArray = e.ImageData;
- byteArray.position = 0;
- fstream.writeBytes(byteArray);
- fstream.close();
- */
- captureBTN.visible = true;
- saveBTN.visible = false;
- discardBTN.visible = false;
- fileName.text = "";
- fileName.visible = false;
- }
- private function discardCapture(e:MouseEvent):void {
- addChild(vid);
- removeChild(bitmap);
- captureBTN.visible = true;
- saveBTN.visible = false;
- discardBTN.visible = false;
- fileName.text = "";
- fileName.visible = false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement