• Android调用相机拍照并返回路径和调用系统图库选择图片


    调用系统图库:

    Intent intent = new Intent(Intent.ACTION_PICK,MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    startActivityForResult(intent, REQUEST_CODE_IMAGE);

    获取图片路径

    @Override
     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
       super.onActivityResult(requestCode, resultCode, data);
       if (requestCode == REQUEST_CODE_IMAGE && resultCode == RESULT_OK) {

          Uri uri = data.getData();
          Cursor cursor = getContentResolver().query(uri, null, null, null,null);
          if (cursor != null && cursor.moveToFirst()) {
              String path = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA));
        }

       }

     }
    调用相机返回路径1:

    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    startActivityForResult(intent, REQUEST_CODE_CAMERA);

    @Override
     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
       super.onActivityResult(requestCode, resultCode, data);

       if (requestCode == REQUEST_CODE_CAMERA && resultCode == RESULT_OK) {

          Bundle bundle = data.getExtras();
         // 获取相机返回的数据,并转换为Bitmap图片格式,这是缩略图
          Bitmap bitmap = (Bitmap) bundle.get("data");

       }
     }


    调用相机返回路径2:

    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    //path为保存图片的路径,执行完拍照以后能保存到指定的路径下

    File file = new File(path);

    Uri imageUri = Uri.fromFile(file );

    intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
    startActivityForResult(intent, REQUEST_CODE_CAMERA);

    @Override
     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
       super.onActivityResult(requestCode, resultCode, data);

       if (requestCode == REQUEST_CODE_CAMERA && resultCode == RESULT_OK) {

           //直接取之前保存的路径

       }
     }

  • 相关阅读:
    使用Python往手机发送短信(基于twilio模块)
    春&风
    故乡
    非常完美
    风 记忆
    风誓
    MATLAB的循环结构
    你要的快乐
    夕颜
    MATLAB的基本元素
  • 原文地址:https://www.cnblogs.com/exmyth/p/8417634.html
Copyright © 2020-2023  润新知