I’m working on a gallery where I want to rotate the view automatically based on the pictures orientation. So for example, two photos:
- 1200w x 800h pixels
- 550w x 800h pixels
Now to determine which is portrait, I just need to check if height > width? Is that the only way? Can someone suggest a better way?
Thanks!
Your technique to determine if the image is in portrait seems nice and simple. Is there some reason you’re reluctant to use that approach? Hard to think of a more logical solution.
By the way, rather than rotating the view if the picture’s orientation is different than the screen, in my gallery I personally default to “aspect fill” if my image’s height-to-width ratio is close to the aspect ratio of the current view (I think my threshold is 10%), and I use “aspect fit” otherwise (and I also give them a user interface for toggling between aspect fit and aspect fill, or better yet you could offer pinch-zoom). If the user wants to rotate the device to change orientation to maximize the experience, they can, but I’m personally not a fan of forcing them to do so unless there is some extremely compelling to do so (i.e., the app just couldn’t possibly function in the other orientation).