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],然后再 ...
随机推荐
- Linux基础学习-使用Squid部署代理缓存服务
使用Squid部署代理缓存服务 Squid是Linux系统中最为流行的一款高性能代理服务软件,通常作为Web网站的前置缓存服务,能够代替用户向网站服务器请求页面数据并进行缓存.Squid服务配置简单. ...
- verilog RTL编程实践之四
1.verilog平时三个级别: 1.gate level: and or not xor 2.RTL level: reg comb seq 3.behavior:+ – * / 2.system ...
- perl学习之:shift/unshift
perl中shift 和unshift 操作 2008-02-02 11:18:04| 分类: Perl语言|举报|字号 订阅 ############################### ...
- JavaScript正则表达式-非捕获性分组
非捕获性分组定义子表达式可以作为整体被修饰但是子表达式匹配结果不会被存储. 非捕获性分组通过将子表达式放在"?:"符号后. str = "img1.jpg,img2.jp ...
- Android兼容性测试GTS-环境搭建、测试执行、结果分析
GTS的全称是Google Mobile Services Test Suite,所谓的Google Mobile Services即谷歌移动服务,是谷歌开发并推动Android的动力,也是Andro ...
- Knockout v3.4.0 中文版教程-4-通过监控数组工作
2.通过监控数组工作 1. 监控数组 如果你想检测或者响应一个对象的改变,你用observables.如果你想检测和响应一个集合的改变,使用observableArray.这个在很多情况下都非常有用, ...
- MarkdownPad 2 HTML 渲染错误解决办法
MarkdownPad 2 HTML 渲染错误解决办法 1. 安装SDK工具包 Awesomium 1.6.6 SDK 2. 安装渲染插件Microsoft’s DirectX End-User Ru ...
- Android App性能自动化评测方法
前言 App运行在设备上的性能表现也是质量保障的一个重要环节.因此,当我们确保了基本功能的准确之后,还需要有一定的方法评测App在不同设备上的性能表现.本文将从性能指标,评测方法,自动化体系建设等三个 ...
- python 多线程、多进程、协程性能对比(以爬虫为例)
基本配置:阿里云服务器低配,单核2G内存 首先是看协程的效果: import requests import lxml.html as HTML import sys import time impo ...
- hlg 1580 tell me the length
智力题,观察上一行,有几个数字. 比如,S[1]=1; S[2]=11; S[3]=21; S[4]=1211; 这样就可以观察出来,序列一是1个1 ---> S[2] = 11 ; 序列二是 ...