• 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);
                }
            }
        }
    
    
    
    }
  • 相关阅读:
    (Power Strings)sdutoj2475
    KMP(http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2772)
    spfa 判断负环 (转载)
    图的存储
    图结构练习——判断给定图是否存在合法拓扑序列(sdutoj)
    poj1753Flip Game(dfs)
    poj2524(简单并查集)
    VC++ GetModuleFileName()获取路径字符串中带波浪线~
    VC++ : error LNK2005: ... already defined in *.obj
    InstallSheild的一些常量
  • 原文地址:https://www.cnblogs.com/gisoracle/p/5009437.html
Copyright © 2020-2023  润新知