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. 目标检测之积分图---integral image 积分图2

    前面在图像处理一栏中涉及到boxfilter 的时候,简单介绍过积分图,就是每个像素点是左边和上边的累加和,这样的话可以方便均值和方差,以及直方图统计的相关运算,这里再次结合网络资源重新单独对积分图做 ...

  2. 海康DS NVR播放URL规则

    URL规定:rtsp://username:password@<address>:<port>/Streaming/Channels/<id>(?parm1=val ...

  3. python中的类的成员变量以及property函数

    1 python类的各种变量 1.1 全局变量 在类外定义的变量. 1.2 类变量 定义在类里面,所有的函数外面的变量.这个变量只有一份,是所有的对象共有的.在类外用“类.”来引用. 1.3 实例变量 ...

  4. wepy原理研究

    像VUE一样写微信小程序-深入研究wepy框架 https://zhuanlan.zhihu.com/p/28700207 wepy原理研究 虽然wepy提升了小程序开发体验,但毕竟最终要运行在小程序 ...

  5. go签名算法设计

    Go by Example 中文:Base64编码 https://books.studygolang.com/gobyexample/base64-encoding/

  6. C++笔记之用户定义的转换

    用户定义的转换(User-defined Conversion) 是一种将一个类类型转换为另一种类型的机制 语法 operator conversion-type-idexplicit operato ...

  7. 阿里妈妈-RAP项目的实践(2)

    接口详情 (id: 32872) Mock数据 接口名称 datalist1 请求类型 get 请求Url /datas/list1 接口描述 数据列表 请求参数列表 变量名 含义 类型 备注 响应参 ...

  8. 青岛理工ACM交流赛 J题 数格子算面积

    数格子算面积 Time Limit: 1000MS Memory limit: 262144K 题目描述 给你一个多边形(用’\’和’/’表示多边形的边),求多边形的面积. 输入  第一行两个正整数h ...

  9. AttributeError: module 'tensorflow' has no attribute 'sub'

    官方的例子:运行之后出现以下错误 # 进入一个交互式 TensorFlow 会话. import tensorflow as tf sess = tf.InteractiveSession() x = ...

  10. codeforces B. Marathon 解题报告

    题目链接:http://codeforces.com/problemset/problem/404/B 题目意思:Valera 参加马拉松,马拉松的跑道是一个边长为a的正方形,要求Valera从起点( ...