Android对图像进行旋转

图像旋转时,旋转后的图像和旋转之前的图像不一样。
我使用了两种方法对图像进行处理。为什么旋转后的图片不全?是因为旋转中心的问题?还是旋转后图像大小的问题?
我应该怎么修改下面代码,使图像旋转后的结果更加准确。

这个是拍摄的原图

img

方法一对图像进行旋转处理

                             Bitmap bitmap=LeftFragment.bitmap;
                            Mat dest=new Mat();
                            Mat mat = CommonImage.bitmapToMat(bitmap);                                   
                            Mat rotationMatrix2D = Imgproc.getRotationMatrix2D(new Point(mat.cols() / 2, mat.rows() / 2), 90, 1);
                            Imgproc.warpAffine(mat,dest,rotationMatrix2D,mat.size());

处理后的图片

img

方法二对图像进行旋转处理


```java
                             Bitmap bitmap=LeftFragment.bitmap;
                             int width = bitmap.getWidth();
                            int height = bitmap.getHeight();
                            Matrix matrix = new Matrix();
                            matrix.postRotate(90);
                            Bitmap rotatedBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);                

处理后的图片

img

很明显你显示图片的承载容器的问题(你可以旋转之后打印输出图片的信息的,建议检查ImageView的ScaleType等),Bitmap处理建议直接使用Matrix