萌アンドロイド子とツーショット撮影ができるアプリを公開


萌アンドロイド子とツーショット撮影ができるアプリを公開しました。
萌アンドロイド子とツーショット撮影!! - Android Market
https://market.android.com/details?id=air.androikoCharaCamera
こんな感じにツーショットが撮れます!!

今回はAlchemyなJpegエンコーダーとタッチによるキャラクターの移動ができるようになっています。あと、バックやホームボタンでアプリが完全に終了するようにしました。
今後の予定としてはやはりパーティクルを使った演出と簡単な画像処理をしてみたいと思います(^_^)
ソースはこちら。

<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        xmlns:mx="library://ns.adobe.com/flex/mx"
        actionBarVisible="false" chromeColor="#FFFFFF" contentBackgroundColor="#FFFFFF"
        creationComplete="view1_creationCompleteHandler(event)" overlayControls="true"
        tabBarVisible="false">
    <fx:Script>
        <![CDATA[
            import cmodule.aircall.CLibInit;
            import mx.events.FlexEvent;
            //アプリ初期化
            private var cam:Camera;
            protected function view1_creationCompleteHandler(event:FlexEvent):void
            {
                this.addEventListener(KeyboardEvent.KEY_DOWN , onKey );
                this.addEventListener(Event.DEACTIVATE , onDeactivateHandler);
                cam = Camera.getCamera();
                cam.setMode(640,480,5);
                var vd:Video =  new Video(cam.width,cam.height);
                vd.rotation = 90;
                vd.x = 480;
                vd.attachCamera(cam);
                myUI.addChild(vd);
            }
            //終了イベント
            protected function onDeactivateHandler( e:Event ):void{
                NativeApplication.nativeApplication.exit();
            }
            //ホームキーなど押された場合
            private function onKey( e:KeyboardEvent ):void
            {
                switch(e.keyCode){
                    case Keyboard.BACK:
                        trace("BACK");
                        NativeApplication.nativeApplication.exit();
                        break;
                    case Keyboard.MENU:
                        trace("MENU");
                        NativeApplication.nativeApplication.exit();
                        break;
                    case Keyboard.SEARCH:
                        trace("SEARCH");
                        break;
                }
            }
            //カメラキャプチャー
            private var lib : Object;
            private var init:CLibInit;
            private var baout:ByteArray;
            private var ba:ByteArray;
            private var bmd:BitmapData = new BitmapData(480,680);
            protected function btnImage_clickHandler(event:MouseEvent):void
            {
                //キャプチャーされた画像を表示しておく(プレビュー)
                cover.visible = true;
                bmd = new BitmapData(480,680);
                bmd.draw(canvas);
                capturedImage.source = bmd;
                captureImageShow.play();
                soundCapture.play();
            }
            //画像保存
            private function doSave():void{
                btnImage.bottom = -10;
                //メッセージの表示
                messageBase.visible = true;
                messageTxt.text = "SDカードに画像を保存しています";
                //Alchemyの準備
                init = new CLibInit();
                lib = init.init();
                baout = new ByteArray();
                ba = bmd.getPixels( new Rectangle(0,0,480,680) );
                ba.position = 0;
                if ( baout ){
                    baout.clear();
                }else{
                    baout = new ByteArray();
                }
                //非同期でJPG保存
                lib.encodeAsync( compressFinished, ba, baout, 480 , 680 , 90, 10 );
            }
            //画像をJPGエンコード完了・画像保存
            private var date:Date = new Date();
            private function compressFinished( out:ByteArray ):void
            {
                cover.visible = false;
                //メッセージの表示
                messageTxt.text = "保存しました!";
                messageBase.visible = false;
                //画像の保存
                var fileName:String = date.getFullYear() +"_"+ (date.getMonth()+1) +"_"+ date.getDay() +"_"+ date.getHours() +"_"+ date.getMinutes() +"_"+ date.getSeconds() + "_"+ + date.getMilliseconds() + ".jpg";
                var file:File = File.documentsDirectory.resolvePath(fileName);
                var stream:FileStream = new FileStream();
                stream.open(file, FileMode.WRITE);
                stream.writeBytes(baout);
                stream.close();
                soundSaved.play();
                ba.clear();
                baout.position = 0;
                btnImage.bottom = 0;
                captureImageSave.play();
            }
            //保存ボタンクリックイベント
            protected function saveBtn_clickHandler(event:MouseEvent):void
            {
                saveBtn.alpha = 0;
                disposeBtn.alpha = 0;
                doSave();
            }
            //キャンセルボタンクリックイベント
            protected function disposeBtn_clickHandler(event:MouseEvent):void
            {
                cover.visible = false;
                captureImageCancel.play();
                saveBtn.alpha = 0;
                disposeBtn.alpha = 0;
            }
        ]]>
    </fx:Script>
    <fx:Declarations>
        <!--サウンドエフェクト-->
        <mx:SoundEffect id="soundCapture"   target="{this}" useDuration="false" source="@Embed('assets/caputer.mp3')"/>
        <mx:SoundEffect id="soundSaved"     target="{this}" useDuration="false" source="@Embed('assets/saved.mp3')"/>
        <s:Fade id="btnShow" targets="{[saveBtn,disposeBtn]}" alphaFrom="0" alphaTo="1"/>
        <s:Fade id="btnHide" targets="{[saveBtn,disposeBtn]}" alphaFrom="1" alphaTo="0"/>
        <s:Move id="captureImageShow" target="{capturedCanvas}" yFrom="{-capturedCanvas.height}" yTo="0" duration="1000" effectEnd="{btnShow.play()}"/>
        <s:Move id="captureImageSave" target="{capturedCanvas}" yFrom="0" yTo="{capturedCanvas.height}" duration="1000"/>
        <s:Move id="captureImageCancel" target="{capturedCanvas}" yFrom="0" yTo="{-capturedCanvas.height}" duration="1000"/>
    </fx:Declarations>
    <s:Group width="480" height="800" clipAndEnableScrolling="true" horizontalCenter="0" verticalCenter="0">
        <!--写真-->
        <s:Image id="bgImage" verticalCenter="0" horizontalCenter="0" source="@Embed('assets/bg.jpg')"/>
        <s:Group id="canvas" width="480" height="680" clipAndEnableScrolling="true" horizontalCenter="0" verticalCenter="0">
            <s:Group width="433" height="632" clipAndEnableScrolling="true" horizontalCenter="0" verticalCenter="0">
                <s:Rect width="100%" height="100%" visible="true">
                    <s:fill>
                        <s:SolidColor color="0x000000" alpha="1"/>
                    </s:fill>
                </s:Rect>
                <mx:UIComponent id="myUI" width="480" height="640" horizontalCenter="0" verticalCenter="0"/>
                <s:Image id="logoImage" horizontalCenter="0" top="30" source="@Embed('assets/logo.png')"
                         mouseDown="{logoImage.startDrag()}" mouseUp="{logoImage.stopDrag()}" mouseOut="{logoImage.stopDrag()}"/>
                <s:Image id="charaImage" right="10" bottom="40" source="@Embed('assets/chara.png')"
                         mouseDown="{charaImage.startDrag()}" mouseUp="{charaImage.stopDrag()}" mouseOut="{charaImage.stopDrag()}"/>
            </s:Group>
            <s:Image id="frameImage" verticalCenter="0" horizontalCenter="0" source="@Embed('assets/frame.png')" alpha="0.99"
                     mouseChildren="false" mouseFocusEnabled="false" mouseEnabled="false"/>
        </s:Group>
        <s:Image id="btnImage" horizontalCenter="0" bottom="0" source="@Embed('assets/btn.png')" click="btnImage_clickHandler(event)"/>
        <!--オーバーレイ-->
        <s:Rect id="cover" width="100%" height="100%" visible="false">
            <s:fill>
                <s:SolidColor color="0x0000" alpha="1"/>
            </s:fill>
        </s:Rect>
        <!--キャプチャー画像と保存・キャンセルボタン-->
        <s:Group id="capturedCanvas" width="480" height="800" y="-800" horizontalCenter="0" clipAndEnableScrolling="true">
            <s:Image id="capturedImage" width="480" height="640" horizontalCenter="0" verticalCenter="0"/>
            <s:Image id="saveBtn" source="@Embed('assets/saveBtn.png')" click="saveBtn_clickHandler(event)" bottom="10" left="10" alpha="0"/>
            <s:Image id="disposeBtn" source="@Embed('assets/disposeBtn.png')" click="disposeBtn_clickHandler(event)" bottom="10" right="10" alpha="0"/>
        </s:Group>
        <!--メッセージボックス-->
        <s:Group id="messageBase" horizontalCenter="0" verticalCenter="0" visible="false" showEffect="Fade" hideEffect="Fade">
            <s:Rect width="400" height="102" radiusX="10" radiusY="10">
                <s:fill>
                    <s:SolidColor color="0xffccff" alpha="0.8"/>
                </s:fill>
            </s:Rect>
            <s:Label id="messageTxt" text="" horizontalCenter="0" verticalCenter="0" color="0xd900bd"/>
        </s:Group>
    </s:Group>
</s:View>