PHP,MySQL,Flexな日々+イラストとか このページをアンテナに追加 RSSフィード

2011-07-02

3Dビューワー

| 10:54 | 3Dビューワー - PHP,MySQL,Flexな日々+イラストとか を含むブックマーク 3Dビューワー - PHP,MySQL,Flexな日々+イラストとか のブックマークコメント

f:id:haru-komugi:20110701171705j:image

Optimus Pad L-06C等の2眼カメラで撮った映像を赤青のレイヤーを使用して合成してAndroid端末で3Dが見えるようにします。


Optimus Padで撮影した動画はこのように1つの画面に2つの映像が入る形式ですので、Flash側で左半分と右半分を切り取って1つの動画にしてあげます。

f:id:haru-komugi:20110702111036j:image

こんな動画を

f:id:haru-komugi:20110702111200j:image

こんな感じに


ソースはこちら

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"  backgroundColor="0x333333"
			   xmlns:s="library://ns.adobe.com/flex/spark" creationComplete="application1_creationCompleteHandler(event)">
	<fx:Style source="video3dTest.css"/>
	<fx:Script>
		<![CDATA[
			import mx.events.FlexEvent;
			
			import org.osmf.events.TimeEvent;
			
			private var mat:Matrix = new Matrix();
			private var bd0:BitmapData = new BitmapData(160 , 240 );
			private var bd1:BitmapData = new BitmapData(160 , 240 );
			private var bd3:BitmapData = new BitmapData( 160 , 240 );
			protected function application1_creationCompleteHandler(event:FlexEvent):void
			{
				mat.tx = -160;
			}
			
			//メガネで見る用
			private function setImage():void
			{
				bd0.draw( myMovie );
				bd0.draw( myImageCover0 , null , null , "screen" );
				myImage0.source = new Bitmap( bd0 );

				bd1.draw( myMovie , mat );
				bd1.draw( myImageCover1 ,null , null , "screen" );
				myImage1.source = new Bitmap( bd1 );
				
				bd3.draw( myImage0);
				bd3.draw( myImage1 ,null,null,"multiply");
				myImage3.source = new Bitmap( bd3 );
			}

			protected function button1_clickHandler(event:MouseEvent):void
			{
				btn.visible = false;
				isPlaying = true;

				this.addEventListener(Event.ENTER_FRAME , onTimer );
			}
			private function onTimer( e:Event ):void
			{
				myMovie.play();
				setImage();
			}
			protected function myMovie_completeHandler(event:TimeEvent):void
			{
				this.removeEventListener(Event.ENTER_FRAME , onTimer );
				btn.visible = true;
				isPlaying = false;
			}
			private var isPlaying:Boolean = false;
			protected function myImage3_clickHandler(event:MouseEvent):void
			{
				if( isPlaying){
					myMovie.pause();
					isPlaying = false;
				}else{
					myMovie.play();
					isPlaying = true;
				}
			}
		]]>
	</fx:Script>
	<fx:Declarations>
		<!-- 非ビジュアルエレメント (サービス、値オブジェクトなど) をここに配置 -->
	</fx:Declarations>
	<s:VideoDisplay complete="myMovie_completeHandler(event)"  id="myMovie" source="movie.flv" width="320" height="240" visible="false"/>
	<s:Image id="myImageCover1" width="320" height="240" source="@Embed('red.jpg')" visible="false"/>
	<s:Image id="myImageCover0" width="320" height="240" source="@Embed('blue.jpg')" visible="false"/>
	<s:Image id="myImage3" verticalCenter="0" horizontalCenter="0" width="160" height="240" scaleX="{this.width/myImage3.width*0.8}" scaleY="{myImage3.scaleX*0.8}"
			 click="myImage3_clickHandler(event)" buttonMode="true"/>
	<s:HGroup>
		
	
	<s:Image id="myImage0" width="160" height="240" scaleX="0.5" scaleY="0.5"/>
	<s:Image id="myImage1" width="160" height="240" scaleX="0.5" scaleY="0.5"/>
	</s:HGroup>
	<s:Button id="btn" bottom="20" width="209" label="再生" click="button1_clickHandler(event)"
			  horizontalCenter="0"/>
</s:Application>

どうにもこうにも重いのとうまく赤青で合成してくれてない気がするのでだれか改造してほしいなぁ。


参考リンク

赤青メガネで物体をさらに立体的に
PaperVision3Dでの赤青メガネで3D

2011-06-30

モバイルFlexでのQRコードリーダーの作成方法

| 16:47 | モバイルFlexでのQRコードリーダーの作成方法 - PHP,MySQL,Flexな日々+イラストとか を含むブックマーク モバイルFlexでのQRコードリーダーの作成方法 - PHP,MySQL,Flexな日々+イラストとか のブックマークコメント

f:id:haru-komugi:20110630163750j:image

QRコードリーダーの作成をやってみました。

さすがにリアルタイムでの処理という訳にはいきませんが、比較的軽い動作で認識します。


まず、zxingが必要なのでダウンロードします。

ダウンロードして解凍したら、「xing/actionscript/core/src/com」のcomフォルダをFlexのプロジェクトsrcにコピーします。


実行時にライブラリでのエラーが出ますが、適度にコメントアウトすれば問題ありません。

DecoderResult.as
//import mx.controls.List;

BufferedImageLuminanceSource.mxml
//import mx.controls.Image;

ソースはこちら

<?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" title="QRCodeReader">
	<fx:Script>
		<![CDATA[
			import com.google.zxing.BarcodeFormat;
			import com.google.zxing.BinaryBitmap;
			import com.google.zxing.BufferedImageLuminanceSource;
			import com.google.zxing.DecodeHintType;
			import com.google.zxing.Result;
			import com.google.zxing.client.result.ParsedResult;
			import com.google.zxing.client.result.ResultParser;
			import com.google.zxing.common.GlobalHistogramBinarizer;
			import com.google.zxing.common.flexdatatypes.HashTable;
			import com.google.zxing.qrcode.QRCodeReader;
			
			import spark.components.VideoDisplay;
			private var camera:Camera;
			private var videoDisplay:Video = new Video();
			private var qrReader:QRCodeReader;
			private var cameraStarted:Boolean = false;
			
			//ボタンクリックイベント
			protected function btn_clickHandler(event:MouseEvent):void
			{
				//ボタンのラベル名によって実行する関数を分ける
				if( ( event.target as Button ).label == "Start Camera" ){
					setCamera();
				}else{
					decodeSnapshot();
				}
			}
			//カメラ設定とステージへ追加
			protected function setCamera():void
			{
				if (Camera.isSupported)
				{					
					camera=Camera.getCamera();
					camera.setMode(640, 480, 24);
					videoDisplay.x = 360;
					videoDisplay.y = 40;
					sv.addChild(videoDisplay);
					videoDisplay.attachCamera(camera);
					videoDisplay.rotation=90;
					qrReader=new QRCodeReader();
					btn.label = "Scan Now";
					lbl.text = "";
					cameraStarted = true;
				}
				else {
					lbl.text = "no camera found";
				}
			}
			//カメラ画像のスナップショット
			private var bmd:BitmapData;
			public function decodeSnapshot():void
			{
				lbl.text="checking...";
				bmd=new BitmapData(640, 480);
				bmd.draw(videoDisplay, null, null, null, null, true);
				videoDisplay.cacheAsBitmap=true;
				videoDisplay.cacheAsBitmapMatrix=new Matrix;
				decodeBitmapData(bmd, 640, 480);
				bmd.dispose();
				bmd=null;
				System.gc();
			}
			
			//送られて画像からデコード
			public function decodeBitmapData(bmpd:BitmapData, width:int, height:int):void
			{
				var lsource:BufferedImageLuminanceSource=new BufferedImageLuminanceSource(bmpd);
				var bitmap:BinaryBitmap=new BinaryBitmap(new GlobalHistogramBinarizer(lsource));
				
				var ht:HashTable=null;
				ht=this.getAllHints();
				
				var res:Result=null;
				try {
					res=qrReader.decode(bitmap, ht);
				}
				catch (event:Error) {
				}
				
				if (res == null) {
					videoDisplay.clear();
					lbl.text="nothing decoded";
				}
				else {
					var parsedResult:ParsedResult=ResultParser.parseResult(res);
					lbl.text=parsedResult.getDisplayResult();
					sv.removeChild(videoDisplay);
					cameraStarted = false;
					btn.label = "Start Camera";
				}
			}
			public function getAllHints():HashTable
			{
				var ht:HashTable=new HashTable;
				ht.Add(DecodeHintType.POSSIBLE_FORMATS, BarcodeFormat.QR_CODE);
				return ht;
			}
		]]>
	</fx:Script>
	<fx:Declarations>
	</fx:Declarations>
	<s:VGroup width="100%" horizontalAlign="center" id="vg">
		<s:SpriteVisualElement id="sv" width="480" height="480"/>
		<s:Label id="lbl" text="" />
		<s:Button id="btn" label="Start Camera" width="220" height="93" click="btn_clickHandler(event)"/>
	</s:VGroup>
</s:View>

参考リンク


How do I add a QR code reader to my Flex mobile application?
どうやってモバイルでQRコード認識するの?ほとんどこのソースを使っております。

zxing
ActionScript用のコード認識ライブラリがあります

masuzmasuz 2011/07/27 15:58 はじめまして。masuzと申します。
大変参考にさせて頂いています。

QRコードリーダを以下の環境で実行してみたのですが、
QRコードを1つも認識してくれませんでした。
何かアドバイス頂ければと思います。

ZXing 1.7
FlashBuilder4.5.1
Galaxy Tab
権限は、INTERNETとCAMERAだけ許可。

haru-komugiharu-komugi 2011/08/03 12:52 masuzさんこんにちわ

QRコードの認識率はかなーり低い感じです。

大きめのQRコードを印刷して正面から撮ってみると認識するかと思います。

あとGalaxyTabはカメラ周りが重くフレームレートが出ないためそれも影響している可能性もあります。

JMSJMS 2011/09/06 18:36 はじめまして、JMSと申します。
困ったときに度々参考にさせて頂いてます。
私もほぼ同一ソースでQRコードリーダーを作ろうとしたのですが、GalaxyS2で全く認識されません。
QRコード読取以前に、VideoオブジェクトにattachCameraするだけで以下のような状態です。
http://jmsnews.blog38.fc2.com/blog-entry-12.html

GalaxySでは認識率は低いものの、一応正常に動作するようです。
GalaxyS2自体のバグなのかなと思っているのですが、何か情報をお持ちでしたらアドバイスを頂けないでしょうか。

ZXing 1.7
FlashBuilder4.5.1
GalaxyS2
です。

2011-02-20

萌え萌えな会津あかべこたんと一緒に記念撮影!

| 16:29 | 萌え萌えな会津あかべこたんと一緒に記念撮影! - PHP,MySQL,Flexな日々+イラストとか を含むブックマーク 萌え萌えな会津あかべこたんと一緒に記念撮影! - PHP,MySQL,Flexな日々+イラストとか のブックマークコメント

f:id:haru-komugi:20110220162711j:image

萌え萌えな会津あかべこたんと一緒に記念撮影!をリリースしましたのでお知らせです。



f:id:haru-komugi:20110220162926p:image


こんな感じに一緒にツーショット撮影ができます。


キャラクターやアイコンはドラッグして、移動することができるので撮影時に遊んでみてくださいませ。


会津あかべこキャラカメラ - Android Market

https://market.android.com/details?id=air.aizuAkabekoCharaCamera&feature=search_result


Flex4プログラミング入門

Flex4プログラミング入門


Flex&Flash Builder 4 による Webアプリケーション開発ガイドブック

Flex&Flash Builder 4 による Webアプリケーション開発ガイドブック


Flex4を始めるならこの2冊が入門書として読みやすいです。

2011-02-15

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

| 18:33 | 萌アンドロイド子とツーショット撮影ができるアプリを公開 - PHP,MySQL,Flexな日々+イラストとか を含むブックマーク 萌アンドロイド子とツーショット撮影ができるアプリを公開 - PHP,MySQL,Flexな日々+イラストとか のブックマークコメント

f:id:haru-komugi:20110215183235j:image

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


萌アンドロイド子とツーショット撮影!! - Android Market

https://market.android.com/details?id=air.androikoCharaCamera


こんな感じにツーショットが撮れます!!

f:id:haru-komugi:20110215183331p:image


今回は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>

肉まんぷるるん検出君アプリを作りました〜

| 12:23 | 肉まんぷるるん検出君アプリを作りました〜 - PHP,MySQL,Flexな日々+イラストとか を含むブックマーク 肉まんぷるるん検出君アプリを作りました〜 - PHP,MySQL,Flexな日々+イラストとか のブックマークコメント

f:id:haru-komugi:20110215121307j:image


せちがらい世の中なので、アプリの中くらいはぷるぷるさせて癒されてもいいでしょうってことで、肉まんぷるるん検出君を作りました。

※AIR for Android なのでAndroid2.2以上が必要です。


f:id:haru-komugi:20110215121904j:image


アプリの説明としては、画像の中の”肉まんっぽいの”を自動で検出して、ぷるぷる揺らすことができます。人物とかにしてみるといろいろと面白いことができます。

SDカードからの画像も読み込みOKなので好きな画像でもいけます。


おバカなアプリですが、いろんな技術が入っていますので、ぜひぷろぷるさせてくださいませ。


肉まんぷるるん検出君 - Android Market

https://market.android.com/details?id=air.nikuman_pururun


今後のアップデートとして

  • カメラモード
  • マイクモード
  • マニュアルモード

を予定しています。

2011-02-11

会津えろうそくまつりアプリをリリースしました〜

| 14:17 | 会津えろうそくまつりアプリをリリースしました〜 - PHP,MySQL,Flexな日々+イラストとか を含むブックマーク 会津えろうそくまつりアプリをリリースしました〜 - PHP,MySQL,Flexな日々+イラストとか のブックマークコメント


f:id:haru-komugi:20110211141459j:image


会津えろうそくまつりアプリをリリースしました〜

http://www.aizu-shop.com/kuratto/erousoku2011/


アプリのインストールはこちら

https://market.android.com/details?id=air.erousokuCharaCamera2


ソースコードはこちら

なんだかGalaxyTabだと動作が遅いです(^^;

<?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" contentBackgroundColor="#000000"
		creationComplete="view1_creationCompleteHandler(event)" overlayControls="false"
		tabBarVisible="false" title="Home">
	<fx:Script>
		<![CDATA[
			import mx.events.FlexEvent;
			import cmodule.aircall.CLibInit;			
			
			//キャラクター画像リスト
			[Embed(source="assets/01.png")]private var image_01:Class;
			[Embed(source="assets/02.png")]private var image_02:Class;
			[Embed(source="assets/03.png")]private var image_03:Class;
			[Embed(source="assets/04.png")]private var image_04:Class;
			[Embed(source="assets/05.png")]private var image_05:Class;
						
			//カメラ作成
			private var cam:Camera;
			protected function view1_creationCompleteHandler(event:FlexEvent):void
			{
//				if( Camera.isSupported ){
					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);
//				}else{
//				}
			}
			
			//キャラクター変更
			private var i:int = 1;
			protected function charactor_clickHandler(event:MouseEvent):void
			{
				i++;
				if( i > 5 ){
					i=1;
				}
				charactor.source = this["image_0"+i];
				charactorShow.play();
				soundCharactor.play();
			}
			
			//カメラキャプチャー
			private var lib : Object; 
			private var init:CLibInit;
			private var baout:ByteArray;
			private var ba:ByteArray;

			//画像をJPGエンコード
			protected function captureBtn_clickHandler(event:MouseEvent):void
			{
				//メッセージの表示
				messageBase.visible = true;
				messageTxt.text = "画像を保存しています";
				soundCapture.play();
				
				//Alchemyの準備
				init = new CLibInit();
				lib = init.init();
				baout = new ByteArray();
				
				//キャンバスの描画
				var bmd:BitmapData = new BitmapData(480,640);
				bmd.draw(canvas);
				ba = bmd.getPixels( new Rectangle(0,0,480,640) );
				ba.position = 0;
				if ( baout ){        
					baout.clear();
				}else{ 
					baout = new ByteArray();
				}
				
				//キャプチャーされた画像を表示しておく(プレビュー)
				caputredImage.source = bmd;
				caputredImage.visible = true;
				
				//非同期でJPG保存
				lib.encodeAsync( compressFinished, ba, baout, 480 , 640 , 90, 10 );

			}
			
			//画像をJPGエンコード完了・画像保存
			private var date:Date = new Date();
			private function compressFinished( out:ByteArray ):void            
			{
				caputredImage.visible = false;
				
				//メッセージの表示
				messageTxt.text = "SDカードに保存しました!";
				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;
			}
		]]>
	</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')"/>
		<mx:SoundEffect id="soundCharactor" target="{this}" useDuration="false" source="@Embed('assets/charactor.mp3')"/>

		
		<s:Sequence id="myFadeShow">
			<s:Fade alphaFrom="0" alphaTo="1" duration="1000"/>
		</s:Sequence>
		<s:Sequence id="myFadeHide">
			<s:Fade alphaFrom="1" alphaTo="0" duration="2000"/>	
		</s:Sequence>
		<s:Fade id="charactorShow" alphaFrom="0" alphaTo="1" target="{charactor}"/>
	</fx:Declarations>
	
	<s:Group width="480" height="760" verticalCenter="0" horizontalCenter="0">
		
		
		<s:Image source="@Embed('assets/bg_top.jpg')" top="0"/>
		<s:Image x="0" y="700" source="@Embed('assets/bg_bottom.jpg')"/>
		
		
		<s:Group id="canvas" width="480" height="640" y="60">
			<mx:UIComponent id="myUI" width="100%" height="100%"/>
			<s:Image id="charactor" x="207" y="140" source="@Embed('assets/01.png')" click="charactor_clickHandler(event)"/>
			<s:Image id="bg" x="0" y="0" source="@Embed('assets/bg.png')"/>
		</s:Group>
		
		
		<s:Image id="caputredImage" width="480" height="640" visible="false" y="60" showEffect="Fade" hideEffect="Fade" />
		
		
		<s:Image id="captureBtn" bottom="10" horizontalCenter="0" source="assets/btn.png" click="captureBtn_clickHandler(event)" buttonMode="true" mouseDown="{captureBtn.bottom=2}" mouseUp="{captureBtn.bottom=10}"/>
	
		
		<s:Group id="messageBase" horizontalCenter="0" verticalCenter="0" visible="false" showEffect="myFadeShow" hideEffect="myFadeHide" click="{messageBase.visible=false;}">
			<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>


参考になるページ

読み込み可能なMP3ファイルのフォーマット - 独学ActionScript
WavからMP3へエンコードする際に注意。今回起動音でコンパイルエラーが出ました。

asynchronous jpeg encoding
同期・非同期でJPGエンコードが可能。動作も早い

alchemyJpeg.mxml
AlchemyなJPEGエンコードのサンプル