• 2021/5/29


    1.今日收获内容

    调用系统自带Carema

    我们只需下面一席话语,即可调用系统相机,相机拍照后会返回一个intent给onActivityResult。 intent的extra部分包含一个编码过的Bitmap~

    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));
            }
    }


    2.遇到的问题
    拍照

    3.明天目标

  • 相关阅读:
    zoj 3715 K
    bzoj 2002(弹飞绵羊) 分块
    最大01矩阵(悬线法)
    csu 1809 Parenthesis(线段树)
    csu 1804(有向无环图)
    csu 1803(2016)
    RCC 2017 Qual 1 Mail.Ru, April 2, 2017 Problem C. Magic Artifact
    Unmarshaller解析xml文件
    sax解析xml文件,封装到对象中
    cas环境搭建
  • 原文地址:https://www.cnblogs.com/qiangini/p/14909565.html
Copyright © 2020-2023  润新知