• 5月23日学习日志


    今天学习了使用Camera拍照。

    调用系统自带Carema。

    Intent it = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    startActivityForResult(it,Activity.DEFAULT_KEYS_DIALER);
    
    //重写onActivityResult方法
        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            if(requestCode == Activity.RESULT_OK){
                Bundle bundle = data.getExtras();
                Bitmap bitmap = (Bitmap) bundle.get("data");
                img_show.setImageBitmap(bitmap);
            }
    } 
    //定义一个保存图片的File变量
    private File currentImageFile = null;
    
    //在按钮点击事件处写上这些东西,这些是在SD卡创建图片文件的:
                @Override
                public void onClick(View v) {
                    File dir = new File(Environment.getExternalStorageDirectory(),"pictures");
                    if(dir.exists()){
                        dir.mkdirs();
                    }
                    currentImageFile = new File(dir,System.currentTimeMillis() + ".jpg");
                    if(!currentImageFile.exists()){
                        try {
                            currentImageFile.createNewFile();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
    
                    Intent it = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                    it.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(currentImageFile));
                    startActivityForResult(it, Activity.DEFAULT_KEYS_DIALER);
                }
    
    //onActivityResult:
     @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            if (requestCode == Activity.DEFAULT_KEYS_DIALER) {
            img_show.setImageURI(Uri.fromFile(currentImageFile));
            }
    }
  • 相关阅读:
    Jwt访问api提示401错误 Authorization has been denied for this request
    git commit的规范
    postman中如何使用OAuth
    在outlook中查找Skype的聊天记录
    nuget sources
    NuGet version
    Forcing restore from package sources
    同时打印多个worksheets
    Redis使用认证密码登录
    Linux wait函数详解
  • 原文地址:https://www.cnblogs.com/20193925zxt/p/14910681.html
Copyright © 2020-2023  润新知