【问题标题】:Saving camera images android .... they're roated 90 degrees保存相机图像android ....它们旋转了90度
【发布时间】:2012-12-09 20:11:14
【问题描述】:

我正在使用 commonware 的相机示例来尝试创建一个拍照的 Android 应用。预览显示相机旋转了 90 度,我已经通过应用进行了更正:

camera.setDisplayOrientation(90);

但是,图像仍以另一种方式旋转 90 度保存。如何调整这一点,以便在保存图像时,它们与查看器的“方面”保存在相同的“方面”?

请指教, TIA

【问题讨论】:

    标签: android android-intent android-camera


    【解决方案1】:

    根据this post ,这仅在某些设备中发生,并且取决于制造商。

    我设法通过检测设备的方向角度并相应地应用旋转来解决此问题,如下所示:

                ExifInterface exitInterface = new ExifInterface(imagePath);
    
                int orientation = exitInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);
                int degree = 0;
    
                switch (orientation){
                case ExifInterface.ORIENTATION_ROTATE_90:
                    degree = 90;
                    break;
                case ExifInterface.ORIENTATION_ROTATE_180:
                    degree = 180;
                    break;
                case ExifInterface.ORIENTATION_ROTATE_270:
                    degree = 270;
                    break;
                }
    

    然后我使用自定义方法旋转我的位图:

        public static Bitmap rotateImage(Bitmap src, float degree) 
    {
            // create new matrix
            Matrix matrix = new Matrix();
            // setup rotation degree
            matrix.postRotate(degree);
            Bitmap bmp = Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true);
            return bmp;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-20
      • 1970-01-01
      • 1970-01-01
      • 2013-07-20
      • 1970-01-01
      • 1970-01-01
      • 2019-07-29
      • 2013-10-30
      相关资源
      最近更新 更多