Android Camera Intent: how to get full sized photo?

前端 未结 7 1456
遇见更好的自我
遇见更好的自我 2020-11-22 16:35

I am using intent to launch camera:

Intent cameraIntent = new Intent(
    android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
getParent().startActivityForResu         


        
相关标签:
7条回答
  • 2020-11-22 17:13

    Open Camera and save image into some specific directory

    private String pictureImagePath = "";
    private void openBackCamera() {
        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
        String imageFileName = timeStamp + ".jpg";
        File storageDir = Environment.getExternalStoragePublicDirectory(
                Environment.DIRECTORY_PICTURES);
        pictureImagePath = storageDir.getAbsolutePath() + "/" + imageFileName;
        File file = new File(pictureImagePath);
        Uri outputFileUri = Uri.fromFile(file);
        Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);               
        cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
        startActivityForResult(cameraIntent, 1);
    }
    

    Handle Image

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == 1) {
        File imgFile = new  File(pictureImagePath);
            if(imgFile.exists()){        
           Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
           ImageView myImage = (ImageView) findViewById(R.id.imageviewTest);
           myImage.setImageBitmap(myBitmap);
    
            }
        }
    
    }
    
    0 讨论(0)
提交回复
热议问题