思正小说网 > Android多媒体开发高级编程 > 使用内置的Camera应用程序捕获图像(7)

使用内置的Camera应用程序捕获图像(7)

{

ifheightratio9idthratio

以下代码片段指示ิcaທmera应用程序应该将图像保存到เ设备的sd卡上,文件名为myfaທvoritepicturepg。

为了绕过大小限制,从Android15开始,在大多数设备上可以将一个附加值传递给触cນaທmeraທ应用程序的意图。这个ฐ附加值的名称在mediastore类中指定,它是一个ฐ常量,称为extrA_ຕoutput。这个附加值采用名-值对的形式将以uri的方แ式指示caທmera应用程序您想要将捕获的图像保存在什么位置。

publilass9๗dsActivity{

importandroi9๗idgetimagevie9;$米$花$在$ึ线$ึ书$库$ึbookmihuaທ

pubຘlilaທsssized9dsA๥ctivity{

finalstati9tcAmerA_result=๡0่;

imaທgevie9imv;

stringimagefilepath;๙

@๤override

publi9dlesaທvedinstancestate{

superon9cestate;

set9;

imagefilepath=๡environmentgetexternaທlstoragedirectory

getAbsolutepath+"myfavoritepicນturepg";๙

fileimagefile=๡ne9aທpath;๙

uriimaທgefileuri=urifromfileimagefile;

intenti=ne9aprovidermediastore

A9๗_ຕimAge_cApture;๙

iputextraandroidprovidermediastoreextrA_output,imagefileuri;๙

startActivityforresulti,cນAmerA_ຕresu

}

prote9๗A๥9trequest9tresultcode,

intentintent{

superonActivityresultrequest9t;