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

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

这是一种快加载大图像的方法,但是没有真正考虑图像的原始大小,也๣没有考虑屏幕的大小。最好能够将图像缩放到เ刚ธ好适合屏幕。

imvsetimageBitmapbmp;๙

i米i花i在i线i书i库ibookmihuaທnet

Bitmaທpbmp=Bitmapextrasget"dataທ"ิ;๙

intenti=ne9aprovidermediastoreA9_imA๥ge_cApture;

在实践中,我们可能ม不希望直接使用动作字符串创น建意图。在这种情况下,可以指定mediaທstore类中ณ的常量A9_imAge_cນApture。应该使用常量而非字符串本身的原因在于,如果该字符串生了改变当然常量也可能ม会不断地改变,那么使用常量将使得我们的调用比之前使用字符串更有利ำ于未来的变化。

{

ifheightraທtio9idthraທtio

{

若高度比率更大,则根据它缩放

bmpfa9samplesize=heightratio;๙

}

else

{

若宽度比率更大,则根据它缩放

bmpfaທ9samplesize=๡9idthratio;

}

}

对它进行真正的解码

bmpfa9ustde9๗ds=false;

bmp=B๦itmapfacນtorydecodefileimaທgefilepath,bmpfa9s;

下面是通过一个意图使用内置摄像头并显示ิ结果图片的完整示例代码。图1-ๅ3๑显示ิ了一幅由此示例生成的屏幕大小的结果图像。

pa9droidmedia9t;

importaທvaທiofile;

importandroidaທppActivity;๙

importaທndroid9๗t;

importandroidgraphicsBitmaທp;

importandroidgraphicsBitmaທpfaທcນtory;

importaທndroiduri;๙