zoukankan      html  css  js  c++  java
  • 摄像头的应用(数值传递)

    package com.androidstudy.uicomponenttest;
    
    import androidx.annotation.Nullable;
    import androidx.appcompat.app.AppCompatActivity;
    
    import android.content.Intent;
    import android.graphics.Bitmap;
    import android.os.Bundle;
    import android.provider.MediaStore;
    import android.view.View;
    import android.widget.Button;
    import android.widget.ImageView;
    
    public class CameraActivity extends AppCompatActivity {
        private Button btnCamera;
        private ImageView ivImage;
        private final int CAMERA_REQUEST = 10; //双方认可,这个是标志
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_camera);
            initView();
        }
    
        @Override
        protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
            switch (requestCode){
                case CAMERA_REQUEST:
                    if(resultCode == RESULT_OK){
                        Bitmap bitmap = (Bitmap) data.getExtras().get("data");
                        ivImage.setImageBitmap(bitmap);
                    }
                    break;
            }
        }
    
        public void initView(){
            ivImage = findViewById(R.id.iv_capture_photo);
            btnCamera = findViewById(R.id.btn_camera_invoke);
            btnCamera.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    //启动本机的摄像头
                    //如何调用本机的摄像头 ACTION是关键
                    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                    //启动系统拍照程序,并将拍摄的照片返回显示在ImageView组件中
                    startActivityForResult(intent,CAMERA_REQUEST);
                }
            });
        }
    }
  • 相关阅读:
    LeetCode 100. 相同的树(Same Tree) 2
    LeetCode 680. 验证回文字符串 Ⅱ(Valid Palindrome II) 1
    MySQL索引操作
    MySQL数据库的一些方法使用
    Anaconda安装新模块
    源码下载
    mongodb内建角色
    windows server 2008开启共享文件设置
    MySQL配置说明
    MySQL的连接数
  • 原文地址:https://www.cnblogs.com/Master-Sun/p/14259538.html
Copyright © 2011-2022 走看看