正文

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

Android多媒体开发高级编程 作者:(美)艾佛瑞


它需要在项目的layout/main.xml 文件中添加如下内容:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

>

<ImageView android:id="@+id/ReturnedImageView"android:layout_width=

"wrap_content"android:layout_height="wrap_content"></ImageView>

</LinearLayout>

为了完成上述示例,以下是AndroidManifest.xml 文件的内容。

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

android:versionCode="1"

android:versionName="1.0"package="com.apress.proandroidmedia.ch1

.cameraintent">

<application android:icon="@drawable/icon" android:label=

"@string/app_name">

<activity android:name=".CameraIntent" android:label="@string/app_name">

<intent-filter> 

<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />

</intent-filter> 

</activity> 

</application> 

<uses-sdk android:minSdkVersion="4" />

</manifest>

在此示例中,Camera应用程序在一个通过意图传递的附加值(extra)中返回图像,而该意图将在onActivityResult方法中传递给主调活动。附加值的名称为“data”,它包含一个Bitmap对象,需要从泛型对象将它强制转换过来。

//从意图中获取附加值

Bundle extras = intent.getExtras();

//从附加值中获取返回的图像

Bitmap bmp = (Bitmap) extras.get("data");

 


上一章目录下一章

Copyright © 读书网 www.dushu.com 2005-2020, All Rights Reserved.
鄂ICP备15019699号 鄂公网安备 42010302001612号