Android系统拍照源码
个人对于Android系统拍照的一些总结:一种自定义图片拍照路径 ,另一种直接利用Android拍照后经过处理的缩略图
特别注意第一种方式需要增加SDK读写权限: <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 下面直接上源码
package com.example.camerademo; import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException; 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.provider.MediaStore;
import android.view.View;
import android.widget.ImageView; public class MainActivity extends Activity { public static final int REQUEST_CAMERA_CODE = 100;
public static final int REQUEST_CAMERA_AUTO = 101;
ImageView mIv;
String path; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mIv = (ImageView) findViewById(R.id.iv);
path = Environment.getExternalStorageDirectory() + "/" + "temp.jpg";
} public void doClick1(View v) {
Intent intent = new Intent (MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(path)));
startActivityForResult(intent, REQUEST_CAMERA_CODE);
}
public void doClick2(View v) {
Intent intent = new Intent (MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, REQUEST_CAMERA_AUTO);
} @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(resultCode == RESULT_OK) {
if(requestCode == REQUEST_CAMERA_CODE ) {
FileInputStream fis = null;
try {
fis = new FileInputStream(path);
Bitmap bitmap = BitmapFactory.decodeStream(fis);
if(bitmap != null) {
mIv.setImageBitmap(bitmap);
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally{
if(fis != null) {
try {
fis.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} } else if(requestCode == REQUEST_CAMERA_AUTO) {
Bundle bundle = data.getExtras();
Bitmap bitmap = (Bitmap) bundle.get("data");
if(bitmap != null) {
mIv.setImageBitmap(bitmap);
}
}
} } }
<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"
tools:context="${relativePackage}.${activityClass}" > <TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" /> <Button
android:id="@+id/startCamera"
android:onClick="doClick1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="17dp"
android:text="startCamera_custome_address" /> <ImageView
android:id="@+id/iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/startCamera"
android:layout_centerVertical="true"
android:layout_marginLeft="32dp" /> <Button
android:id="@+id/button1"
android:onClick="doClick2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/startCamera"
android:layout_below="@+id/startCamera"
android:layout_marginTop="41dp"
android:text="start_camera_auto_addres" /> </RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.camerademo"
android:versionCode="1"
android:versionName="1.0" > <uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".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> </manifest>
Android系统拍照源码的更多相关文章
- Android系统定制和源码开发以及源码编译(附视频)
Android系统定制配套视频: 为了把Android系统源码定制和编译的课程讲完,从准备到录制完所有的视频,一共花去了近半年的时间,前前后后各种下载源码,编译源码,系统不兼容,版本适配,虚拟机配置困 ...
- 【转】Android 4.3源码的下载和编译环境的安装及编译
原文网址:http://jingyan.baidu.com/article/c85b7a641200e0003bac95a3.html 告诉windows用户一个不好的消息,windows环境下没法 ...
- Android 开源项目源码解析(第二期)
Android 开源项目源码解析(第二期) 阅读目录 android-Ultra-Pull-To-Refresh 源码解析 DynamicLoadApk 源码解析 NineOldAnimations ...
- android狼人杀源码,桌面源码,猎豹快切源码
Android精选源码 android实现狼人杀app源码 android实现精心打造的Android基础框架源码 android热门电影的客户端源码 android 实现桌面的Launcher源码 ...
- Ubantu16.04进行Android 8.0源码编译
参考这篇博客 经过测试,8.0源码下载及编译之后,占用100多G的硬盘空间,尽量给ubantu系统多留一些硬盘空间,如果后续需要在编译好的源码上进行开发,需要预留更多的控件,为了防止后续出现文件权限问 ...
- 第一部分:开发前的准备-第八章 Android SDK与源码下载
第8章 Android SDK与源码下载 如果你是新下载的SDK,请阅读一下步骤了解如何设置SDK.如果你已经下载使用过SDK,那么你应该使用AVD Manager,来更新即可. 下面是构建Andro ...
- Android MIFARE NFCA源码解析
Android MIFARE NFCA源码解析TagTechnology定义了所有标签的共有接口类BasicTagTechnology 实现了TagTechnology的一些接口 再有具体的标签协议继 ...
- [Android 编译(一)] Ubuntu 16.04 LTS 成功编译 Android 6.0 源码教程
本文转载自:[Android 编译(一)] Ubuntu 16.04 LTS 成功编译 Android 6.0 源码教程 1 前言 经过3天奋战,终于在Ubuntu 16.04上把Android 6. ...
- 从谷歌官网下载android 6.0源码、编译并刷入nexus 6p手机
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/fuchaosz/article/details/52473660 1 前言 经过一周的奋战,终于从谷 ...
随机推荐
- SOAPUI使用教程-验证SOAP服务
当soapUI创建一个功能性TestCase 一个很常见的场景是你想一些SOAP / WSDL服务验证响应检查返回正确的结果. 一旦你导入了您想要测试的WSDL服务这样做很容易: 添加一个新的SOAP ...
- js面向对象总结(一)
在 js 中,对象由特性(attribute)构成,特性可以是原始值,也可以是引用值.如果特性存放的是函数,它将被看作对象的方法(method),否则该特性被看作对象的属性(property).在js ...
- python练习
创建一个简单的姓名和编号系统,让用户输入一组人的姓名和编号,实现提供按照编号或姓名排序输出的功能. nums = [] names = [] Afternums = [] Afternames = [ ...
- vmware 虚拟机中添加新网卡无配置文件
系统:centos 6/7 问题: 为虚拟机添加新网卡后,/etc/sysconfig/network-scripts/下无配置文件ifcfg-eth1 #ip addr //显示存在eth ...
- Javascript初学篇章_3(注释/if/switch)
五.javascript的注释 // 单行注释 /* …*/ 多行注释 注:多行注释不能互相嵌套 六.程序流程控制 一.条件语句 if 语法: if(condition) statements1 el ...
- 使用非Web方式从CA申请证书
背景介绍:关于从CA申请证书这点事,网上的那些教程基本都是让我们通过访问https://server/certsrv这样的网页来操作的,我一直希望不依赖IIS就把这事干了,于是就有了下面的文章. 1. ...
- Ajax调用Conrtoller返回数据
前端ajax function doRefund(){ $.ajax({ type: "POST", catch: false, url: "@Url.Action(&q ...
- p4lang/switch make bm-switchsai 出现内存不足导致的Error
报错如下: Compiling : bm::dc.cpp g++: internal compiler error: Killed (program cc1plus) Please submit a ...
- Windows自带压缩解压工具
压缩一个文件: 命令行:makecab fileName.txt fileName.zip 鼠标操作:选中文件-->鼠标右键-->Send to-->Compressed (zipp ...
- Ant和Maven的作用是什么?两者之间功能、特点有哪些区别?
Ant和Maven都是基于Java的构建(build)工具.理论上来说,有些类似于(Unix)C中的make ,但没有make的缺陷. Ant是软件构建工具,Maven的定位是软件项目管理和理解工具. ...