简体   繁体   English

Android中人像模式下的相机方向

[英]Camera orientation in Portrait mode in android

the camera orientation in android with portrait mode gives view with an rotated angle of 90 degrees. android在人像模式下的摄像头方向可提供90度旋转角度的视图。 the link says here as a bug in android and I am using sdk 2.2. 链接在这里说是android中的错误,我正在使用sdk 2.2。 http://code.google.com/p/android/issues/detail?id=1193 http://code.google.com/p/android/issues/detail?id=1193

I have tried all the methods in the link but could not set right the issue. 我已经尝试了链接中的所有方法,但无法解决问题。 Any answers on this issue would be helpful. 关于此问题的任何答案都将有所帮助。 Looking forward for your reply. 期待您的答复。 thanks. 谢谢。

I am not sure how you are going to use those captured image further . 我不确定您将如何进一步使用这些捕获的图像。 . . so if you are going to capture and just display it in an Imageview better rotate it to 90 degree and set the bitmap using the following code 因此,如果要捕获图像并将其显示在Imageview中,则最好将其旋转到90度,并使用以下代码设置位图

public static Bitmap rotate(Bitmap b, int degrees) 
{
    if (degrees != 0 && b != null) 
    {
        Matrix m = new Matrix();

        m.setRotate(degrees, (float) b.getWidth() / 2, (float) b.getHeight() / 2);
        try {
            Bitmap b2 = Bitmap.createBitmap(b, 0, 0, b.getWidth(), b.getHeight(), m, true);
            if (b != b2) 
            {
                b.recycle();
                b = b2;
            }
        } catch (OutOfMemoryError ex) 
        {
           throw ex;
        }
    }
    return b;
}

or if you are going to save it to the SDcard and use it , after taking picture rotate the bitmap using former code and then save it in sdcard . 或者,如果要保存到SD卡并使用它,请在拍照后使用以前的代码旋转位图,然后将其保存在sdcard中。

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

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