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

           探索Android 所提供的内置功能,内置的图像捕获与存储功能为Android 上全部媒体功能提供了一个非常好的切入点,为我们在以后的章节中处理音频和视频奠定了基础。
           如今介绍怎样利用内置的Camera(摄像头)应用程序。
  
package com.example;

import java.io.File;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.view.Display;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView; public class MainActivity extends Activity { final static int CAMERA_RESULT = 0;
ImageView imv;
Button but; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_main);
findViewById();
		but.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
                               /*运行Camera内置摄像头意图*/
Intent i = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i, CAMERA_RESULT); }
});
} private void findViewById() {
but = (Button) findViewById(R.id.but);
imv = (ImageView) findViewById(R.id.img);
} /* 当activity运行完后,就显示照片*/
	@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
Bundle bundle = data.getExtras();
Bitmap bmp = (Bitmap) bundle.get("data");
imv.setImageBitmap(bmp); }
} }




AndroidManifest.xml 配置

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.MainActivity"
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>




activity_main.xml 配置

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" > <ImageView
android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
/> <Button
android:id="@+id/but"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/img"
android:layout_centerInParent="true"
android:text="take_a_picture"/> </RelativeLayout>

Android 照相功能的更多相关文章

  1. Android简单调用相机Camera功能,实现打开照相功能

    在最開始接触Android相机功能之前,先来体验一下Android调用系统照相功能吧 核心代码 Intent intent = new Intent(); //调用照相机 intent.setActi ...

  2. [译]:Xamarin.Android平台功能——位置服务

    返回索引目录 原文链接:Location Services. 译文链接:Xamarin.Android平台功能--位置服务 本部分介绍位置服务以及与如何使用位置提供商服务 Location Servi ...

  3. Android表情功能

    Android表情功能 标签(空格分隔): 未分类 转载自:android edittext插入表情(基于socket方式),并对文中不正确的内容进行整理和修正 [TOC] 涉及知识点: Androi ...

  4. WPFMediaKit照相功能

    最近写的一个WPF照相功能,往各位吐槽,提供优化 在WPF 设计器中添加如下代码 xmlns:wpfmedia="clr-namespace:WPFMediaKit.DirectShow.C ...

  5. Cocos2d-x使用android拍照功能加载照片内存过大,通过另存照片尺寸大小解决

    使用2dx调用android拍照功能,拍照结束后在2dx界面显示拍照照片,如果不对照片做处理,会出现内存过大的问题,导致程序崩溃,如果仅仅另存拍照照片,则照片质量大小均下降,导致照片不够清晰,后来发现 ...

  6. Android定位功能

    不说废话,直接说说实现android定位有关的API吧. 这些API都在android.location包下,一共有三个接口和八个类.它们配合使用即可实现定位功能. 三个接口: GpsStatus.L ...

  7. Android定位功能(二)

    在前文Android定位功能(一)中,已经大致介绍了一下在Android平台中,和定位功能相关的类,并举例获取了位置信息.但是前文是基于Criteria定制了一个标准,通过getBestProvide ...

  8. Android P 功能和 API

    Android P 功能和 API Android P 为用户和开发者引入众多新特性和新功能. 本文重点介绍面向开发者的新功能. 要了解新 API,请阅读 API 差异报告或访问 Android AP ...

  9. Delphi xe7 up1 调用android振动功能

    Delphi xe7 up1 调用android振动功能 振动用到以下4个单元: Androidapi.JNI.App,Androidapi.JNIBridge,Androidapi.JNI.Os,A ...

随机推荐

  1. 4.Swift教程翻译系列——Swift基本运算符

    英文版PDF下载地址http://download.csdn.net/detail/tsingheng/7480427 运算符是指一个特殊的符号,能够用来查看.更改值或者相加.比方说加法运算符+能够讲 ...

  2. 数学之路-python计算实战(2)-初遇pypy

    PyPy是Python开发人员为了更好的Hack Python创建的项目.此外,PyPy比CPython是更加灵活,易于使用和试验,以制定详细的功能在不同情况的实现方法,能够非常easy实施. 该项目 ...

  3. ZeroMQ:云计算时代最好的通讯库

    还在学socket编程吗?还在研究为什么epoll比select更好吗? 噢,不必了! 在复杂的云计算环境中,我们面临的难题远比这个复杂得多. 庞大的服务器集群作为计算云,对来来看或许只是一个简单的搜 ...

  4. 与众不同 windows phone (8) - Tile(磁贴)

    原文:与众不同 windows phone (8) - Tile(磁贴) [索引页][源码下载] 与众不同 windows phone (8) - Tile(磁贴) 作者:webabcd介绍与众不同 ...

  5. Tokyo Tyrant(TTServer)系列(四)-tcrmgr远程管理与调试

    Tokyo Tyrant(TTServer)系列-tcrmgr(远程管理与调试) tcrmgr是TokyoTyrant的管理工具,对ttserver进行管理与执行命令: 通过输入tcrmgr回车,能够 ...

  6. Swift - 开关按钮(UISwitch)的用法

    下面演示如何创建开关,以及监听它值的改变,代码如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 class ViewController: UIV ...

  7. 彻底卸载McAfee和Agent的方法

    1.控制面板中-添加或删除程序中-删除"McAfee VirusScan Enterprise"和"McAfee AntiSpyware Enterprise Modul ...

  8. [Android学习笔记]Unable to execute dex Multiple dex files define:xxxx 问题

    dex filse: Dalvik Execute Files , 即Android虚拟机可执行程序 从字面意思理解是你一个应用中,出现了多个Dex文件定义. 以下情况会出现此错误: 1.你项目中可能 ...

  9. Android本地视频播放器开发--简易播放器原型

    在以前的基础上,将音视频进行合并,音频播放采用OpenSL ES,视频播放采用OpenGL ES2.0进行显示,这次的版本其中音频和视频是在同一个线程,会造成音频断断续续,后续会采用音频使用SDL,视 ...

  10. 以JTextPanel为例Swing的鼠标事件详解

    如下界面可以通过该界面研究一下Swing的鼠标事件: 图中用红粗线圈起来的为JtextPanel,该Panel添加了鼠标事件监听器,鼠标事件监听器有三种,分别为MouseWheelListener,M ...