简体   繁体   English

以人像模式从相机拍摄的加载到画布上的照片为横向

[英]Photos loaded onto canvas taken from a camera in portrait mode are landscape

If I take a photo with my camera in android in portrait mode, and then load it as a bitmap and draw it to a canvas it appears rotated counter clockwise 90 degrees and in landscape orientation. 如果我在人像模式下用相机在android系统中拍摄照片,然后将其作为位图加载并绘制到画布上,则它会逆时针旋转90度并横向移动。 I use BitmapFactory.decodeFile(imagePath); 我使用BitmapFactory.decodeFile(imagePath); to load the image. 加载图像。 Does anyone know why this would happen? 有谁知道为什么会这样?

Please see the answer at Android: Photos force captured in Landscape mode . 请查看Android上的答案:在风景模式下强制捕获照片

The bottom line is, capture preserves the hardware camera orientation, which is landscape in most telephones. 最重要的是,捕获保留了硬件摄像头的方向,这在大多数电话中都是横向的。 You have few ways to find the actual orientation of the device vs. the horizon when the picture was taken, eg the EXIF header of the JPEG file. 您几乎没有办法找到拍摄照片时设备相对于水平线的实际方向,例如JPEG文件的EXIF标头。 Bitmap method that decodes such file does not respect the EXIF info, even if it is present. 解码此类文件的位图方法不考虑EXIF信息,即使存在该信息也是如此。 But you can choose one of the ways to apply rotation to the bitmap after it is loaded. 但是,可以选择一种在位图加载后对其应用旋转的方法。

An alternative is to apply rotation to the captured JPEG file, as described in Lossless JPEG Rotate (90/180/270 degrees) in Java? 另一种方法是将旋转应用于捕获的JPEG文件,如Java中的“ 无损JPEG旋转(90/180/270度)”中所述? . There is even an app on the PlayStore to do it: https://play.google.com/store/apps/details?id=com.lunohod.jpegtool . PlayStore上甚至有一个应用程序可以做到这一点: https : //play.google.com/store/apps/details? id = com.lunohod.jpegtool。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM