How to make Android Camera Intent return full size picture

前端 未结 2 1084
终归单人心
终归单人心 2020-12-09 13:33

I am using the jengelsma code from this post Capture Image from Camera and Display in Activity to get an image from the camera.

When I get the returned image it is o

2条回答
  •  时光说笑
    2020-12-09 14:07

    start intent for camera

    private void takeFromCamera() {
            Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {
                File exportDir = new File(Environment.getExternalStorageDirectory(), "TempFolder");
                if (!exportDir.exists()) {
                    exportDir.mkdirs();
                }
    
                String fileName = "/" + UUID.randomUUID().toString().replaceAll("-", "") + ".jpg";
                mTempCameraPhotoFile = new File(exportDir,fileName);
                Log.d(LOG_TAG, fileName);
                takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mTempCameraPhotoFile));
                startActivityForResult(takePictureIntent, REQUEST_CAMERA);
            }
        }
    

    capture result in onActivityResult

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
    
        if (resultCode == Activity.RESULT_OK) {
    
            if  (requestCode == REQUEST_CAMERA) {
    
    
                if (requestCode == REQUEST_CAMERA) {
                    String filePath = mTempCameraPhotoFile.getPath();
                    Log.d(LOG_TAG, filePath);
    
                    /*
                    // extracted file path can be load into imageview for example with Picasso loader
                    Uri uri = Uri.fromFile(new File(mReportImageList.get(position).getUrl()));
                    Picasso.with(mContext)
                            .load(uri)
                            .fit()
                            .centerCrop()
                            .into(ivPhoto);*/
    
    
                }
            }
        }
    }    
    

    in manifest

    
    
    
    

提交回复
热议问题