简体   繁体   中英

Camera orientation in Portrait mode in android

the camera orientation in android with portrait mode gives view with an rotated angle of 90 degrees. the link says here as a bug in android and I am using sdk 2.2. 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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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