android front and back camera captured picture orientation issue, rotated in a wrong way

后端 未结 5 1300
一整个雨季
一整个雨季 2021-02-05 10:12

I have a camera app in portrait mode which takes pictures from both front and back end cameras.The issue is like the captured images are rotated in a wrong way...

For pr

5条回答
  •  忘了有多久
    2021-02-05 10:36

    try this code snippet

    try {
    
        ExifInterface exif = new ExifInterface(filePath);
        orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);
        //Toast.makeText(getApplicationContext(), ""+orientation, 1).show();
        Log.v("log", "ort is "+orientation);
    
        } catch (IOException e)
        {
            e.printStackTrace();
        }
    

    and then rotate the matrix as per orientation you get

    if (orientation==6)
    {
        Matrix matrix = new Matrix();
        matrix.postRotate(90);
        bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);
    }
    else if (orientation==8)
    {
        Matrix matrix = new Matrix();
        matrix.postRotate(270);
        bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);
    }
    
    else if (orientation==3)
    {
        Matrix matrix = new Matrix();
        matrix.postRotate(180);
        bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true;
    }
    

提交回复
热议问题