1
votes

In my project, i want to select image into gallery and add these inside recycle view. Hovewer when i choose vertical phone camera taken picture, it return reverse height and width. Horizontal camera images turn true. By the way when someone send vertical image from somewhere it will returns true. I see logs and it say : D/height : 2322 , D/width: 4128 for vertical image. But it is opposite .

Here is my get height and width code :

public int drawableWidthFromPath(String path,int width)throws IOException{

        File imgFile = new File(path);
        int newWidth=0;

        if(imgFile.exists())
        {
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inJustDecodeBounds = true;
            BitmapFactory.decodeFile(imgFile.getAbsolutePath(), options);
            int imageHeight = options.outHeight;
            int imageWidth = options.outWidth;


            Log.d("height", String.valueOf(imageHeight));
            Log.d("width", String.valueOf(imageWidth));


            newWidth = width*imageWidth/imageHeight;

        }


        return newWidth;
    }

this code works for : horizontal outsource image, vertical outsource image, horizontal camera image but not works for vertical camera image. By the way i try

Bitmap x = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
x.getHeight();
x.getWidth();

But result is same.Here is some ss about what i am do : wrong size picture true size here

and i look at twitter photo chooser it show picture totally true. Where is my problem. Thanks

1

1 Answers

0
votes

Here Is the solution :

        switch(orientation) {

            case ExifInterface.ORIENTATION_ROTATE_90:
                selectedBitmap =rotateImage(selectedBitmap, 90);
                break;

            case ExifInterface.ORIENTATION_ROTATE_180:
                selectedBitmap =  rotateImage(selectedBitmap, 180);
                break;

            case ExifInterface.ORIENTATION_ROTATE_270:
                selectedBitmap =  rotateImage(selectedBitmap, 270);
                break;

            case ExifInterface.ORIENTATION_NORMAL:
                selectedBitmap =  rotateImage(selectedBitmap, 0);

            default:
                break;
        }