Want to make photo in Android, but it automatically downscales the photo to 160x160px

86 Views Asked by At

Hello fellow programmers. My problem: Every time I made a photo, Android automatically scales it down to 160x160px. I don't know why. Here is my code:

Here I set all the preferences for the camera:

public void ChosenPhoto(String extra) {
        String gallery = "gallery";
        String camera = "camera";

        if (extra.equals(gallery)) {
            Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            intent.setType("image/*");
            intent.putExtra("crop", "true");
            intent.putExtra("return-data", true);
            intent.putExtra("aspectX", 560);
            intent.putExtra("aspectY", 560);
            intent.putExtra("outputX", 560);
            intent.putExtra("outputY", 560);
            intent.putExtra("noFaceDetection", true);
            intent.putExtra("screenOrientation", ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
            startActivityForResult(intent, PICK_FROM_GALLERY);
        } else if (extra.equals(camera)) {
            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, MediaStore.Images.Media.EXTERNAL_CONTENT_URI.toString());
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            intent.putExtra("crop", "true");
            intent.putExtra("aspectX", 560);
            intent.putExtra("aspectY", 560);
            intent.putExtra("outputX", 560);
            intent.putExtra("outputY", 560);
            intent.putExtra("noFaceDetection", true);
            intent.putExtra("screenOrientation", ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            intent.putExtra("return-data", true);
            startActivityForResult(intent, PICK_FROM_CAMERA);
        }

}

Here I use it later on:

Bundle extras = data.getExtras();

                    photoBit = extras.getParcelable("data");
                    ByteArrayOutputStream PhotoStream = new ByteArrayOutputStream();
                    photoBit.compress(Bitmap.CompressFormat.PNG, 100, PhotoStream);
                    photos = PhotoStream.toByteArray();
                    Log.e(TAG, "Width:" + photoBit.getWidth() );

                    ImageView.setImageBitmap(photoBit);

In the ImageView, I later see that it is scaled down. More precise: every time to 160x160px... I have no idea why.

Please help me. If you need more information, just ask for it.

1

There are 1 best solutions below

4
On BEST ANSWER

What is returned in "data" is actually only a thumbnail and not the full-sized photo. It is not possible to get the full-sized image this way, but you need to create a file in which the camera will save it for you. Working example with explanation can be found from http://developer.android.com/training/camera/photobasics.html under title "Save the Full-size Photo".

First you need to create a new File that will store the image. You may want to make sure the file name does not collide with other files (append timestamp).

File file = new File(context.getExternalFilesDir( null ), "photo.jpg");

Then you specify this in the intent:

intent.putExtra( MediaStore.EXTRA_OUTPUT, Uri.fromFile( file ) );
activity.startActivityForResult( intent, REQUEST_TAKE_PHOTO );

In onActivityResult() you will check if photo was actually taken. You will use the File instance that you have created before that now has the image.

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

If you want to put the image from the file into ImageView, you can do this:

Bitmap bmp = BitmapFactory.decodeFile( file.getAbsolutePath() );
imageView.setImageBitmap(bmp);