Search code examples
androiduriandroid-camera-intentonactivityresult

make bitmap using camera intent large


My camera intent bitmap is only 160x120 i think how can i achieved full size bitmap

btw i tried EXTRA_OUTPUT but I dont know how to use it

i have 2 class

and my main class onActivityResult is this

case CAMERA_REQUEST_CODE:
        if (resultCode == RESULT_OK) {
             Bitmap image1 = (Bitmap) data.getExtras().get("data");

            if (currentView == 0) {
                frontView.setScaleType(ScaleType.CENTER);
                 frontView.setImageBitmap(image1);
                isFrontActive = true;
            } else if (currentView == 1) {
                rearView.setScaleType(ScaleType.CENTER);
                rearView.setImageBitmap(camera.getImage());
                isRearActive = true;
            }

        }


        break;

and this is photo.class code

public void openCamera() {

    File file = new File(Environment.getExternalStorageDirectory(),
            "Sample.jpg");

         Uri imgUri = Uri.fromFile(file);
    imagepath = file.getAbsolutePath();

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

     cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, imagepath);
    mActivity.startActivityForResult(cameraIntent, CAMERA_REQUEST_CODE);

}

so they are in a separate class and I dont know how to use EXTRA_OUTPUT please help me and thank you

EDIT:

I call photo.class

by using

photo.openCamera(); on Main Class


Solution

  • I got mine working by converting the Uri to Bitmap

    bitmap = MediaStore.Images.Media.getBitmap(
                            this.getContentResolver(), imageUri);
    

    then I save it using

    MediaStore.Images.Media.insertImage(
                                getContentResolver(), bitmap, "Title",
                                "Desc");
    

    so this is my code for onActivityResult on Main.class

    case 2:
    
            if (resultCode == RESULT_OK) {
                Bitmap bitmap = null;
                Uri imageUri = camera.getImageUri();
                try {
                    bitmap = MediaStore.Images.Media.getBitmap(
                            this.getContentResolver(), imageUri);
                    bitmap = camera.setImage(bitmap);
                } catch (FileNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } finally {
                    if (currentView == 0) {
                        frontView.setImageBitmap(bitmap);
                        isFrontActive = true;
    
                        MediaStore.Images.Media.insertImage(
                                getContentResolver(), bitmap, "Title",
                                "Desc");
                    } else if (currentView == 1) {
                        rearView.setImageBitmap(bitmap);
                        isRearActive = true;
    
                    }
    
                }
    
            }
    
            break;
    
    
    and this is  my Photo.class
    

    private Uri imageUri; // Global

    public void openCamera() {
    
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        File file = new File(Environment.getExternalStorageDirectory(),
                "Cloudstaff_Ron.jpg");
        Uri imgUri = Uri.fromFile(file);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, imgUri);
        this.imageUri = imgUri;
        mActivity.startActivityForResult(intent, 2);
    }