MobileFlex调用摄像头.docx

上传人:b****2 文档编号:18856761 上传时间:2023-04-24 格式:DOCX 页数:19 大小:20.59KB
下载 相关 举报
MobileFlex调用摄像头.docx_第1页
第1页 / 共19页
MobileFlex调用摄像头.docx_第2页
第2页 / 共19页
MobileFlex调用摄像头.docx_第3页
第3页 / 共19页
MobileFlex调用摄像头.docx_第4页
第4页 / 共19页
MobileFlex调用摄像头.docx_第5页
第5页 / 共19页
点击查看更多>>
下载资源
资源描述

MobileFlex调用摄像头.docx

《MobileFlex调用摄像头.docx》由会员分享,可在线阅读,更多相关《MobileFlex调用摄像头.docx(19页珍藏版)》请在冰豆网上搜索。

MobileFlex调用摄像头.docx

MobileFlex调用摄像头

MobileFlex调用摄像头

利用flashair技术可跨平台实现摄像头调用功能,并且实现了拍照并保存照片。

(基于flex4.6开发)

Mxml文件代码如下:

xmlversion="1.0"encoding="GBK"?

>

Applicationxmlns:

fx="

xmlns:

s="library:

//applicationDPI="240"width="480"height="800">

Declarations>

--将非可视元素(例如服务、值对象)放在此处-->

Declarations>

Script>

[CDATA[

importponents.android.alert.AlertDialog;

importflash.events.*;

importflash.media.CameraUI;

importflash.media.MediaType;

importmx.formatters.DateFormatter;

importmx.graphics.codec.JPEGEncoder;

privatevarimgBD:

BitmapData=null;

privatevaralert:

AlertDialog;

privatefunctionini():

void{

SavePic.enabled=false;

if(CameraUI.isSupported==false){

trace("您似乎没有安装摄像头!

");

alert=newAlertDialog();

alert.title="提示";

alert.message="您似乎没有安装摄像头!

";

alert.open(this,true);

}else{

varcameraUI:

CameraUI=newCameraUI();

cameraUI.launch(MediaType.IMAGE);

cameraUI.addEventListener(MediaEvent.COMPLETE,onComplete);

cameraUI.addEventListener(Event.CANCEL,onCancel);

cameraUI.addEventListener(ErrorEvent.ERROR,onError);

}

}

privatevarbitmapData:

BitmapData;

privatevarfileSource:

IEventDispatcher;

privatevarfileDataSource:

IDataInput;

privatevarfileData:

ByteArray;

privatefunctiononComplete(event:

MediaEvent):

void{

varpromise:

MediaPromise=event.dataasMediaPromise;

varloader:

Loader=newLoader();

loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onImageLoaded);

loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,onError);

loader.loadFilePromise(promise);

//如果我不想显示,只是想得到该图片的二进制数据,就象打开一个File一样.用下面的方法.如果不用这个,请把下面的代码注释掉.不然会造成不能显示图片

//--------------Start

fileDataSource=promise.open();

if(promise.isAsync){

fileSource=fileDataSourceasIEventDispatcher;

fileSource.addEventListener(Event.COMPLETE,dataCompleteHandler);

}else{

readFileData();

}

//---------------end

}

privatefunctiondataCompleteHandler(event:

Event):

void{

fileData=newByteArray();

fileDataSource.readBytes(fileData);

}

//读取二进制数据

privatefunctionreadFileData():

void{

fileData=newByteArray();

fileDataSource.readBytes(fileData);

//sendDataToServer(fileData);

}

privatefunctiononCancel(event:

MediaEvent):

void{

trace("您取消了本次拍照!

");

alert=newAlertDialog();

alert.title="提示";

alert.message="您取消了本次拍照!

";

alert.open(this,true);

}

/*

privatefunctiononImageLoaded(event:

Event):

void{

bitmapData=Bitmap(event.currentTarget.content).bitmapData;

varbitmap:

Bitmap=newBitmap(bitmapData);

//determinetheimageorientation

varisPortrait:

Boolean=(bitmapData.height/bitmapData.width)>1.0;

//choosesmallestvaluebetweenstagewidthandheight

varforRatio:

int=Math.min(stage.stageHeight,stage.stageWidth);

//calculatethescalingratiotoapplytotheimage

varratio:

Number;

if(isPortrait){

ratio=forRatio/bitmapData.width;

}else{

ratio=forRatio/bitmapData.height;

}

bitmap.width=bitmapData.width*ratio;

bitmap.height=bitmapData.height*ratio;

if(!

isPortrait){

bitmap.y=bitmap.width;

bitmap.rotation=-90;

}

addChild(bitmap);

Img.source=bitmap;

SavePic.enabled=true;

}

*/

privatefunctiononImageLoaded(e:

Event):

void{

varmediaLoaderInfo:

LoaderInfo=e.targetasLoaderInfo;

mediaLoaderInfo.removeEventListener(Event.COMPLETE,onImageLoaded);

mediaLoaderInfo.loader.removeEventListener(IOErrorEvent.IO_ERROR,onError);

this.Img.source=mediaLoaderInfo.loader;

bitmapData=this.Img.bitmapData;

SavePic.enabled=true;

}

privatefunctiononError(event:

Event):

void{

trace("图像加载错误:

"+event.toString(),"");

alert=newAlertDialog();

alert.title="提示";

alert.message="图像加载错误!

";

alert.open(this,true);

}

privatefunctionsave_pic():

void{

//if(bitmapData){

//varjpg:

JPEGEncoder=newJPEGEncoder();

//varbyt:

ByteArray=jpg.encode(bitmapData);

vardateFormatter:

DateFormatter=newDateFormatter();

dateFormatter.formatString="YYYYMMDDJJNNSS";

varnow:

String=dateFormatter.format(newDate());

varfl:

File=newFile(File.desktopDirectory.resolvePath(now+'.jpg').nativePath);

varfs:

FileStream=newFileStream();

try{

//openfileinwritemode

fs.open(fl,FileMode.WRITE);

//writebytesfromthebytearray

//fs.writeBytes(byt);

fs.writeBytes(fileData);

//closethefile

fs.close();

trace("成功保存图片到本地!

"+File.desktopDirectory.resolvePath(now+'.jpg').nativePath);

alert=newAlertDialog();

alert.title="提示";

alert.message="成功保存图片到本地!

\r\n"+File.desktopDirectory.resolvePath(now+'.jpg').nativePath;

alert.open(this,true);

}catch(e:

Error){

trace(e.message);

}

//}

}

privatefunctiondownloadComplete(event:

Event):

void{

trace("成功保存图片到本地!

");

}

privatefunctionClose():

void{

NativeApplication.nativeApplication.exit();

}

]]>

Script>

Buttonx="43"y="585"label="照相"width="168"height="55"click="ini()"fontSize="24"/>

Buttonx="256"y="585"id="SavePic"label="保存照片"width="160"height="55"click="save_pic()"fontSize="24"/>

Imageid="Img"x="43"y="30"width="371"height="494"scaleMode="stretch"smooth="true"

smoothingQuality="high">

source>

MultiDPIBitmapSourcesource240dpi="@Embed('../bin-debug/dd.jpg')"/>

source>

Image>

Buttonx="145"y="678"width="157"label="退出"click="Close()"/>

Application>

App配置xml文件内容如下:

xmlversion="1.0"encoding="utf-8"standalone="no"?

>

--AdobeAIRApplicationDescriptorFileTemplate.

Specifiesparametersforidentifying,installing,andlaunchingAIRapplications.

xmlns-TheAdobeAIRnamespace:

Thelastsegmentofthenamespacespecifiestheversion

oftheAIRruntimerequiredforthisapplicationtorun.

minimumPatchLevel-TheminimumpatchleveloftheAIRruntimerequiredtorun

theapplication.Optional.

-->

--Auniversallyuniqueapplicationidentifier.MustbeuniqueacrossallAIRapplications.

UsingareverseDNS-stylenameastheidisrecommended.(Eg.com.example.ExampleApplication.)Required.-->

Camera

--Usedasthefilenamefortheapplication.Required.-->

Camera

--ThenamethatisdisplayedintheAIRapplicationinstaller.

Mayhavemultiplevaluesforeachlanguage.Seesamplesorxsdschemafile.Optional.-->

Camera

--Astringvalueoftheformat<0-999>.<0-999>.<0-999>thatrepresentsapplicationversionwhichcanbeusedtocheckforapplicationupgrade.

Valuescanalsobe1-partor2-part.Itisnotnecessarytohavea3-partvalue.

AnupdatedversionofapplicationmusthaveaversionNumbervaluehigherthanthepreviousversion.Requiredfornamespace>=2.5.-->

0.0.0

--Astringvalue(suchas"v1","2.5",or"Alpha1")thatrepresentstheversionoftheapplication,asitshouldbeshowntousers.Optional.-->

---->

--Description,displayedintheAIRapplicationinstaller.

Mayhavemultiplevaluesforeachlanguage.Seesamplesorxsdschemafile.Optional.-->

---->

--Copyrightinformation.Optional-->

---->

--PublisherID.Usedifyou'reupdatinganapplicationcreatedpriorto1.5.3-->

---->

--Settingsfortheapplication'sinitialwindow.Required.-->

--ThemainSWForHTMLfileoftheapplication.Required.-->

--Note:

InFlashBuilder,theSWFreferenceissetautomatically.-->

[此值将由FlashBuilder在输出app.xml中覆盖]

--Thetitleofthemainwindow.Optional.-->

---->

--Thetypeofsystemchrometouse(either"standard"or"none").Optional.Defaultstandard.-->

---->

--Whetherthewindowistransparent.OnlyapplicablewhensystemChromeisnone.Optional.Defaultfalse.-->

---->

--Whetherthewindowisinitiallyvisible.Optional.Defaultfalse.-->

---->

--Whethertheusercanminimizethewindow.Optional.Defaulttrue.-->

---->

--Whethertheusercanmaximizethewindow.Optional.Defaulttrue.-->

---->

--Whethertheusercanresizethewindow.Optional.Defaulttrue.-->

---->

--Thewindow'sinitialwidthinpixels.Optional.-->

---->

--Thewindow'sinitialheightinpixels.Optional.-->

---->

--Thewindow'sinitialxposition.Optional.-->

---->

--Thewindow'sinitialyposition.Optional.-->

---->

--Thewindow'sminimumsize,specifiedasawidth/heightpairinpixels,suchas"400200".Optional.-->

---->

--Thewindow'sinitialmaximumsize,specifiedasawidth/heightpairinpixels,suchas"16001200".Optional.-->

---->

--Theinitialaspect

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 解决方案 > 学习计划

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1