http://www.cnblogs.com/mengyan/archive/2012/09/01/2666636.html

安卓读取视频的几种方式:

详细讲述请参考网址:http://www.cnblogs.com/over140/archive/2011/11/16/2251344.html

一、准备工作

1.用户权限

首先要确保在manifest中声明了对摄像头的使用及其他相关的feature;

manifest中定义:

(1)Camera权限——应用程序必须对请求摄像头的使用权限,代码:

<uses-permission android:name="android.permission.CAMERA" />

(2) Camera Feature——应用程序必须同时声明对camera feature的使用,代码:

<uses-feature android:name="android.hardware.camera" />

(3)以上是两个主要的设置,如果有其他额外功能,比如使用自动对焦,还需要使用:

<uses-feature android:name="android.hardware.camera.autofocus" />

详细内容可以参考文章前面的网站内容;

二、实现方法

1.使用intent通知安卓操作系统

(1)在主activity中使用intent通知内置的摄像机应用;用户在使用摄像进行拍照过后返回主activity图片数据,在主activity 

中加入接收数据的方法,对返回的图像进行操纵;

优点:这种方法比较简单,且利用了android内置的应用,使用于一般性的应用程序开发;

缺点:不够灵活,不适用自定义的方法,可扩展性较差;

(2)调用步骤

通常按以下步骤来提交一个摄像头 intent:

首先,构建一个摄像头 Intent —— 用以下意图类型之一,创建一个请求图像或视频的Intent,

MediaStore.ACTION_IMAGE_CAPTURE —— 向内置摄像头程序请求图像的意图活动类型。

MediaStore.ACTION_VIDEO_CAPTURE —— 向内置摄像头程序请求视频的意图活动类型。

然后,启动摄像头 Intent ——用startActivityForResult()方法执行摄像头 intent。启动完毕后摄像头应用的用户界面就会显 

示在屏幕上,用户就可以拍照或摄像了。

最后,接收Intent结果 —— 在应用程序中设置onActivityResult()方法,用于接收从摄像头 intent返回的数据。当用户拍摄完 

毕后(或者取消操作),系统会调用此方法。

(3)实例

详细代码可见文章顶部网站,本文提供了一个简单的程序:

package cn.edu.zjut.androidcam;

import android.os.Bundle;
import android.provider.MediaStore;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
/**
*
* @ClassName: MainActivity
* @Description:通过intent调用android内置的摄像应用程序
* @author Alfred.M
* @date 2012-9-1 下午2:35:12
*
*/
public class MainActivity extends Activity {
private static final int CAMERA_REQUEST = 1888;
private ImageView imageView; @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.imageView = (ImageView) this.findViewById(R.id.imageView1);
Button photoButton = (Button) this.findViewById(R.id.button1); Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
photoButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);//构造intent
startActivityForResult(cameraIntent, CAMERA_REQUEST);//发出intent,并要求返回调用结果
}
});
} /**
* 接收intent传回的信息
*/
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_REQUEST) {
//System.exit(0);
Bitmap photo = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(photo);
}
}
}

<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" > <TextView
android:id="@+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/hello_world"
tools:context=".MainActivity" /> <ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/app_name" >
</ImageView> <Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/text2"
android:layout_below="@+id/imageView1"
android:layout_marginRight="14dp"
android:layout_marginTop="79dp"
android:text="@string/button" />
</RelativeLayout>

android摄像头获取图像——第一弹的更多相关文章

  1. android摄像头获取图像——第二弹

    使用android内的Camera对象 (1)Camera是控制着摄像头的api,拥有一系列控制摄像头的上层方法:camera类能够调用底层的摄像头接口,完成启动摄像头.预 览摄像头图像.拍照等功能: ...

  2. android摄像头获取图像——第三弹

    相机获取图像的格式问题 android中承认的格式的参考网址为 :http://developer.android.com/reference/android/graphics/ImageFormat ...

  3. ant android打包--学习第一弹

    1. 准备工作 用eclipse创建一个android项目 安装ant和SDK,并且添加到系统环境变量 2.ant 使用 2.1 ant简单的帮助命令 ant -p 2.2 创建ant配置文件%AND ...

  4. GC那些事儿--Android内存优化第一弹

    引言 接App优化之内存优化(序), 作为App优化系列中内存优化的一个小部分. 由于内存相关知识比较生涩, 内存优化中使用到的相关工具, 也有很多专有名词. 对Java内存管理, GC, Andro ...

  5. ROS 教程之 vision : 用各种摄像头获取图像

    可能有很多人想在ROS下学习视觉,先用摄像头获取图像,再用opencv做相应算法处理,可是ROS下图像的采集可不像平常的read一下那么简单,需要借助外部package的使用.而摄像头即可以用笔记本自 ...

  6. Android开源项目第一篇——个性化控件(View)篇

    本文为那些不错的Android开源项目第一篇——个性化控件(View)篇,主要介绍Android上那些不错个性化的View,包括ListView.ActionBar.Menu.ViewPager.Ga ...

  7. Android摄像头:只拍摄SurfaceView预览界面特定区域内容(矩形框)---完整(原理:底层SurfaceView+上层绘制ImageView)

    Android摄像头:只拍摄SurfaceView预览界面特定区域内容(矩形框)---完整实现(原理:底层SurfaceView+上层绘制ImageView) 分类: Android开发 Androi ...

  8. 如何使用 OpenCV 打开摄像头获取图像数据?

    OpenCV 如何打开摄像头获取图像数据? 代码运行环境:Qt 5.9.1 msvc2015 32bit OpenCV 3.3.0 #include "include/opencv2/ope ...

  9. 我的长大app开发教程第一弹:Fragment布局

    在接下来的一段时间里我会发布一个相对连续的Android教程,这个教程会讲述我是如何从零开始开发“我的长大”这个Android应用. 在开始之前,我先来介绍一下“我的长大”:这是一个校园社交app,准 ...

随机推荐

  1. JQuery 如何获取select选中的值

    一.html代码 <select id="ddl"> <option value="100" emoney="12" &g ...

  2. Local Response Normalization 60 million parameters and 500,000 neurons

    CNN是工具,在图像识别中是发现图像中待识别对象的特征的工具,是剔除对识别结果无用信息的工具. ImageNet Classification with Deep Convolutional Neur ...

  3. linux 启动引导器 grub,单用户模式:

    Linux启动引导器 安装linux操作系统的时候就已经将启动引导器安装到硬盘上去了,才能通过硬盘的读取方式启动操作系统. 引导器分为2种: Lilo:功能比较简单,使用比较麻烦,后续发行版中使用gr ...

  4. HTML5 <template>

    http://www.zhangxinxu.com/wordpress/2014/07/hello-html5-template-tag/

  5. Codeforces Round #303 (Div. 2) D. Queue —— 贪心

    题目链接:http://codeforces.com/problemset/problem/545/D 题解: 问经过调整,最多能使多少个人满意. 首先是排序,然后策略是:如果这个人对等待时间满意,则 ...

  6. centos6.5安装jdk

    1.查看Linux环境自带JDK 使用命令:# rpm -qa|grep gcj 显示内容其中包含相应信息# java-x.x.x-gcj-compat-x.x.x.x-xxjpp# java-x.x ...

  7. python sorted函数的小练习

    前两天学习了一下socket编程,在向某大神请教问题时被嫌弃了,有一种还没学会走就想跑的感觉.大神说我现在的水平应该去做一些像是操作文件.序列号等的小练习来加深理解.下面是他给我出的小练习: 1.da ...

  8. multi_socket

    threading_test.py #threading #为什么在命令行可以执行,F5不能执行 #线程处理能导致同步问题 from socketserver import TCPServer,Thr ...

  9. POJ1226(strstr)

    Substrings Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 13348   Accepted: 4722 Descr ...

  10. mysql函数之七:replace() MySQL批量替换指定字段字符串

    mysql replace实例说明: UPDATE tb1 SET f1=REPLACE(f1, 'abc', 'def'); REPLACE(str,from_str,to_str) 在字符串 st ...