2

I'm facing a weird situation concerning picture size and aspect ratio but maybe it will be obvious for some, I hope.

I have a RecyclerView in which I insert picture (and video), the width of picture is forced (maxWidth/2).

What I want to do is to keep the original aspect ratio and set the height of the picture according the width value. Then I had to retrieve the initial size of picture from the user private gallery :

BitmapFactory.Options options = new BitmapFactory.Options();
            options.inJustDecodeBounds = true;
            BitmapFactory.decodeFile(file, options);
            fileHeight = options.outHeight;
            fileWidth = options.outWidth;

I calculated the factor between width and height, but I found that it could not work when the picture sizes were inverted. I made some tests on several camera and some take picture for instance in 720x1280 and other 1280x720 resolution whereas the picture is exactly the same.

Then I tried to inverted the calcul factor according the initial sizes but it's not working because of picture format (landscape...). This is the same thing with video.

How can I achieve this ?

nicover
  • 2,213
  • 10
  • 24
  • 1
    "it could not work" and "it's not working" aren't descriptive enough to help people understand your problem. Instead, describe what the exact observed behavior is and what the expected/intended behavior should be. For UI issues, a screenshot or video is usually helpful. Include the exact text of any error messages, including the full [stack trace](/a/23353174) of any exceptions, if applicable, as well as which line of code the stack trace points to. Please see [ask] and [How to create a Minimal, Reproducible Example](/help/minimal-reproducible-example). – Ryan M May 02 '20 at 00:27
  • 1
    I understand the problem because i am facing the same issue. He wants to know a way that tells you if a photo or video has its width and height reversed. It happens on some devices with the built-in camera... You take a picture and the details shows you a resolution 4100x1900 but displayed as 1900x4100. The problem is that the camera handles the rotation and gives anyway 4100px in width even if it's wrong because the picture is taken in full screen vertical. Thus, if you retrieve the width & height of the picture, you have a wrong preview and only the human eye can know if it's reversed. – Tom3652 May 02 '20 at 11:08

0 Answers0