android 拍照预览
<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 拍照预览的更多相关文章
- 【腾讯优测干货分享】Android 相机预览方向及其适配探索
本文来自于腾讯bugly开发者社区,未经作者同意,请勿转载,原文地址:http://dev.qq.com/topic/583ba1df25d735cd2797004d 由于Android系统的开放策略 ...
- Android Camera2 预览,拍照,人脸检测并实时展现
https://www.jianshu.com/p/5414ba2b5508 背景 最近需要做一个人脸检测并实时预览的功能.就是边检测人脸,边在预览界面上框出来. 当然本人并不是专门做 ...
- Android Camera2 预览功能实现
1. 概述 最近在做一些关于人脸识别的项目,需要用到 Android 相机的预览功能.网上查阅相关资料后,发现 Android 5.0 及以后的版本中,原有的 Camera API 已经被 Camer ...
- Android Wear预览版——尝鲜
前两天Google推出了Android Wear的SDK,稍稍的瞧了一眼,发现这个预览版的功能还是比较简单的,只有一个通知转发的功能,不过就这么一个功能,带来的效果却是Very Good~~ 功能:发 ...
- Android RecyclerView预览item
参考: Android Tools Attributes listItem 和 Sample Data 的用法 笔记 tools:text TextView可以实现预览,不影响实际的效果 例如: to ...
- SurfaceView实现拍照预览
一.布局代码 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:andro ...
- Android 摄像头预览悬浮窗
用CameraX打开摄像头预览,显示在界面上.结合悬浮窗的功能.实现一个可拖动悬浮窗,实时预览摄像头的例子. 这个例子放进了单独的模块里.使用时注意gradle里的细微差别. 操作摄像头,打开预览.这 ...
- Android 摄像头预览悬浮窗,可拖动,可显示在其他app上方
市面上常见的摄像头悬浮窗,如微信.手机QQ的视频通话功能,有如下特点: 整屏页面能切换到一个小的悬浮窗 悬浮窗能运行在其他app上方 悬浮窗能跳回整屏页面,并且悬浮窗消失 我们探讨过用CameraX打 ...
- Android Camera 预览图像被拉伸变形的解决方法【转】
问题描述: 预览图像被拉伸变形 问题原因: 由于预览图像大小跟SurfaceView 大小不一致引起 解决方法: 获取系统支持的所有预览尺寸[getSupportedPictureSizes],然后再 ...
随机推荐
- js的工厂模式
工厂模式: 什么叫工厂模式,工厂就是大家大脑里想的那样,一个流水线作业的一个东西,只需要满足刚需就可以了,一个人,只干一件事,最后串起来,就是一个事件. 首先需要说一下工厂模式.工厂模式根据抽象程度的 ...
- docker系列之镜像服务器
docker 的镜像服务器 docker-registry 是 docker 项目的组成部分. 前面在谈 docker 的命令时, 它的 pull/push 命令就是和镜像服务器打交道. 并且, do ...
- 《offline coolbook》笔记
https://jakearchibald.com/2014/offline-cookbook/ 在install中对依赖进行缓存 self.addEventListener('install', f ...
- 如何用纯 CSS 创作背景色块变换的按钮特效
效果预览 在线演示 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/XYKdwg 可交互视频教 ...
- asyn_fifo
//Module Name:afifo_ctrl //Description:parameterized afifo module afifo_ctrl( clk_push, rst_push_n, ...
- python--MySQl单表查询
一. 关键字的执行优先级(重点) from where group by having # 使用是要放在group by 后面而且前面必须有group by select distinct # 去重 ...
- PyCharm 社区版创建Django项目的一个方法
PyCharm 社区版创建项目无法选择Django等项目,只能选择Python项目. 你在进行练习的时候为了方便,可以用过期了的PyCharm专业版在可用的30分钟内创建社区版本不支持的项目,再用Py ...
- 四丶人生苦短,我用python【第四篇】
1 基本数据类型 数字 int 字符串 str 布尔值 bool 列表 list 元组 tuple 字典 dict >>>type( ...
- python3--__call__拦截调用
__call__拦截调用 当实例调用时,使用__call__方法.不,这不是循环定义:如果定义了,Python就会为实例应用函数调用表达式运行__call__方法.这样可以让类实例的外观和用法类似于函 ...
- 最近项目中公用的JS
var closeid = 1; var isneedpwd = 0; var editor1; var NoCheckUrl = 0;//适用于框架 不验证权限 !=0验证 function Erp ...