三星手机选择图片旋转问题
Android开发机型比较多可能会遇到比较奇葩的问题,在选择本地图片上传的时候三星手机会遇到图片旋转90°的情况,这需要我们自己判断图片是否旋转,然后在将其旋转过来就好:
private String dealPic(String fillPath) {//针对三星手机拍照旋转的问题if (getPictureDegree(filePath) != 0) {bitmap = toturn(bitmap, readPictureDegree(filePath));}String path = BitmapUtils.saveImage(this, bitmap);return path;}
获取图片旋转角度:
public static int getPictureDegree(String path) {int degree = 0;try {ExifInterface exifInterface = new ExifInterface(path);int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);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;}} catch (IOException e) {e.printStackTrace();}return degree;}
若图片旋转了就将其旋转回0°:
/*** 旋转图片** @param img* @return*/public Bitmap toturn(Bitmap img, int degree) {Matrix matrix = new Matrix();matrix.postRotate(+degree);int width = img.getWidth();int height = img.getHeight();img = Bitmap.createBitmap(img, 0, 0, width, height, matrix, true);return img;}
以上即可解决,目前只在三星手机遇到该问题。
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
