个人对于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系统拍照源码的更多相关文章

  1. Android系统定制和源码开发以及源码编译(附视频)

    Android系统定制配套视频: 为了把Android系统源码定制和编译的课程讲完,从准备到录制完所有的视频,一共花去了近半年的时间,前前后后各种下载源码,编译源码,系统不兼容,版本适配,虚拟机配置困 ...

  2. 【转】Android 4.3源码的下载和编译环境的安装及编译

    原文网址:http://jingyan.baidu.com/article/c85b7a641200e0003bac95a3.html  告诉windows用户一个不好的消息,windows环境下没法 ...

  3. Android 开源项目源码解析(第二期)

    Android 开源项目源码解析(第二期) 阅读目录 android-Ultra-Pull-To-Refresh 源码解析 DynamicLoadApk 源码解析 NineOldAnimations ...

  4. android狼人杀源码,桌面源码,猎豹快切源码

    Android精选源码 android实现狼人杀app源码 android实现精心打造的Android基础框架源码 android热门电影的客户端源码 android 实现桌面的Launcher源码 ...

  5. Ubantu16.04进行Android 8.0源码编译

    参考这篇博客 经过测试,8.0源码下载及编译之后,占用100多G的硬盘空间,尽量给ubantu系统多留一些硬盘空间,如果后续需要在编译好的源码上进行开发,需要预留更多的控件,为了防止后续出现文件权限问 ...

  6. 第一部分:开发前的准备-第八章 Android SDK与源码下载

    第8章 Android SDK与源码下载 如果你是新下载的SDK,请阅读一下步骤了解如何设置SDK.如果你已经下载使用过SDK,那么你应该使用AVD Manager,来更新即可. 下面是构建Andro ...

  7. Android MIFARE NFCA源码解析

    Android MIFARE NFCA源码解析TagTechnology定义了所有标签的共有接口类BasicTagTechnology 实现了TagTechnology的一些接口 再有具体的标签协议继 ...

  8. [Android 编译(一)] Ubuntu 16.04 LTS 成功编译 Android 6.0 源码教程

    本文转载自:[Android 编译(一)] Ubuntu 16.04 LTS 成功编译 Android 6.0 源码教程 1 前言 经过3天奋战,终于在Ubuntu 16.04上把Android 6. ...

  9. 从谷歌官网下载android 6.0源码、编译并刷入nexus 6p手机

    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/fuchaosz/article/details/52473660 1 前言 经过一周的奋战,终于从谷 ...

随机推荐

  1. xcode8插件无法使用

    一,xcode8无法使用插件的问题 创建新的XcodeSigner代码证书,并执行"sudo codesign -f -s XcodeSigner /Applications/Xcode.a ...

  2. sql server 权限体系

    --给sql server添加一个新用户[账号,密码,数据库名] execute  sp_addlogin 'baishi', '123','db'; execute  sp_addlogin 'wx ...

  3. ajax pagination 布局刷新

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xht ...

  4. js中for in的用法

    for(var i=0;i<len;i++)这样的用法一般都可以用for in 来替代. 例如: var a = ["a","b","c&quo ...

  5. Java技巧(代码简略)

    1.将数组循环显示 int[] num = new int[]{1,3,5,7,9}; int currentNum=0; num[++current%num.length];

  6. python实现之决策树

    一.Predict survival on the Titanic 使用泰坦尼克号上的乘客数据,对乘客是否存活进行预测 1.观察数据集合 可能遇到的问题 训练集和测试集特征值得属性并不重合.连续属性和 ...

  7. bug2--工程性错误

    1问题场景:图片上传失败,打印log.http header 有数据.不报错,通过流写入文件后,文件被创建,但是大小为0kb. 执行:df -h 发现linux的磁盘 used 100%. 原来是没有 ...

  8. IE8浏览器不能识别CSS伪类的解决办法。

    1. 方法一:开头加上这两句 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "htt ...

  9. HTML5 头部标签定义

    <!DOCTYPE html> <!-- 使用 HTML5 doctype,不区分大小写 --> <html lang="zh-cmn-Hans"&g ...

  10. Thinking in Java——笔记(16)

    Arrays Why arrays are special There are three issues that distinguish arrays from other types of con ...