<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" > <!-- 定义提示用户点击拍照的标签控件 -->
<TextView
android:id="@+id/Tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="点击拍照预览效果"
/> <!-- 定义显示照相结果的图片控件 -->
<ImageView
android:id="@+id/Iv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"
android:layout_above="@+id/Btn" /> <!-- 定义用户点击拍照的按钮控件 -->
<Button
android:id="@+id/Btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="点击按钮使用摄像头拍照"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" /> </RelativeLayout>
package com.example.yanlei.yl;

import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import android.text.Html;
import android.text.Html.ImageGetter; import java.util.regex.Matcher;
import java.util.regex.Pattern; import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;
import android.widget.Button; import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView; public class MainActivity extends AppCompatActivity {
// 定义布局中的点击拍照的Button控件
private Button btn;
// 定义布局中给用户的提示内容的控件
private TextView Tv;
// 定义布局中显示的图片控件
private ImageView Iv; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//得到浏览器中的控件对象
findView();
//设置对象的监听器
setListener(); } private void setListener() {
// 设置btn的点击监听器
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//设置Intent的参数为通过摄像头获取的ACTION_IMAGE_CAPTURE
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
//启动activity返回照片结果,设置返回的requestCode为1
startActivityForResult(intent, 1);
}
});
} private void findView() {
// 得到布局中的开始加载的Button的对象
btn = (Button) findViewById(R.id.Btn);
// 得到布局中的开始加载的EditText的对象
Tv = (TextView) findViewById(R.id.Tv);
// 得到布局中的开始加载的ImageView的对象
Iv = (ImageView) findViewById(R.id.Iv);
} /*
* 系统的intent结果返回回调函数
*/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
//接受用户通过其他activity返回的数据
super.onActivityResult(requestCode, resultCode, data);
//如果请求的requestCode为1的话,进行处理
if (requestCode == 1) {
//得到返回的处理状态,如果是成功得到了照片返回RESULT_OK值
if (resultCode == RESULT_OK) {
//成功得到照片后,得到data对象中的data值,并且转换为Bitmap对象
Bitmap bmPhoto = (Bitmap) data.getExtras().get("data");
//设置Iv的显示对象为此Bitmap
Iv.setImageBitmap(bmPhoto);
}
}
} }

android 拍照预览的更多相关文章

  1. 【腾讯优测干货分享】Android 相机预览方向及其适配探索

    本文来自于腾讯bugly开发者社区,未经作者同意,请勿转载,原文地址:http://dev.qq.com/topic/583ba1df25d735cd2797004d 由于Android系统的开放策略 ...

  2. Android Camera2 预览,拍照,人脸检测并实时展现

    https://www.jianshu.com/p/5414ba2b5508 背景     最近需要做一个人脸检测并实时预览的功能.就是边检测人脸,边在预览界面上框出来.     当然本人并不是专门做 ...

  3. Android Camera2 预览功能实现

    1. 概述 最近在做一些关于人脸识别的项目,需要用到 Android 相机的预览功能.网上查阅相关资料后,发现 Android 5.0 及以后的版本中,原有的 Camera API 已经被 Camer ...

  4. Android Wear预览版——尝鲜

    前两天Google推出了Android Wear的SDK,稍稍的瞧了一眼,发现这个预览版的功能还是比较简单的,只有一个通知转发的功能,不过就这么一个功能,带来的效果却是Very Good~~ 功能:发 ...

  5. Android RecyclerView预览item

    参考: Android Tools Attributes listItem 和 Sample Data 的用法 笔记 tools:text TextView可以实现预览,不影响实际的效果 例如: to ...

  6. SurfaceView实现拍照预览

    一.布局代码 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:andro ...

  7. Android 摄像头预览悬浮窗

    用CameraX打开摄像头预览,显示在界面上.结合悬浮窗的功能.实现一个可拖动悬浮窗,实时预览摄像头的例子. 这个例子放进了单独的模块里.使用时注意gradle里的细微差别. 操作摄像头,打开预览.这 ...

  8. Android 摄像头预览悬浮窗,可拖动,可显示在其他app上方

    市面上常见的摄像头悬浮窗,如微信.手机QQ的视频通话功能,有如下特点: 整屏页面能切换到一个小的悬浮窗 悬浮窗能运行在其他app上方 悬浮窗能跳回整屏页面,并且悬浮窗消失 我们探讨过用CameraX打 ...

  9. Android Camera 预览图像被拉伸变形的解决方法【转】

    问题描述: 预览图像被拉伸变形 问题原因: 由于预览图像大小跟SurfaceView 大小不一致引起 解决方法: 获取系统支持的所有预览尺寸[getSupportedPictureSizes],然后再 ...

随机推荐

  1. 使用 ss 命令查看连接信息

    作用:打印主机socket连接信息,netstate可以做的它都可以做,比netstate 更灵活,而且由于ss使用 tcp_diag 内核模块,所以速度更快. 用法: ss [ OPTIONS ] ...

  2. mysql的字符串处理函数用法

    1.LOCATE函数 LOCATE(substr,str) 返回子串 substr 在字符串 str 中第一次出现的位置.如果子串 substr 在 str 中不存在,返回值为 0.如果substr或 ...

  3. a标签中javascript和void

    <body> <a href="javascript:;">点了无反应</a> <a href="javascript:void ...

  4. verilog behavioral modeling--blocking and nonblocking

                                                                                                 BLOCKIN ...

  5. laravel如何利用数据库的形式发送通知

    具体实现需要分几步: 1.修改驱动为database; 2.创建database的queue表 3.创建任务sendMessage 4.创建发送逻辑dispatch 5.启动队列 接下来我们进行实操: ...

  6. Python3的基本数据类型及常用的方法

    python3的基本数据类型: 在python3当中有这么几种基本的数据类型:int(整形).str(字符串).list(列表).tuple(元组).dict(字典).bool(布尔值)等.数字整体划 ...

  7. Repo command reference

    Repo command reference In this document init sync upload diff download forall prune start status Rep ...

  8. Oracle从入门到精通(笔记)

    一.Oracle11g概述 1.6 启动与关闭数据库实例 1.6.1 启动数据库实例 Oracle数据库实例启动分3个步骤:启动实例,加载数据库,打开数据库: 命令格式:startup [nomoun ...

  9. 使用systemctl命令管理服务mysql

    启动mysql systemctl start mysqld.service 停止mysql systemctl stop mysqld.service 重启mysql systemctl resta ...

  10. main()中的参数argc, argv

    转自:http://blog.csdn.net/eastmount/article/details/20413773 一.main()函数参数 通常我们在写主函数时都是void main()或int ...