android 拍照图片自动旋转了?

来源:互联网 发布:java考试 编辑:程序博客网 时间:2024/04/29 03:50
 拍照完后获取的图片自动旋转了,解决方案:1.先获取图片旋转的角度2.旋转回来。微笑
/** * @desc <pre>获取图片旋转的角度</pre> * @author Weiliang Hu * @date 2013-9-18 * @param path * @return */public static int readPictureDegree(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;}    /**     * @desc <pre>旋转图片</pre>     * @author Weiliang Hu     * @date 2013-9-18     * @param angle     * @param bitmap     * @return     */public static Bitmap rotaingImageView(int angle, Bitmap bitmap) {// 旋转图片 动作Matrix matrix = new Matrix();matrix.postRotate(angle);System.out.println("angle2=" + angle);// 创建新的图片Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);bitmap.recycle();return resizedBitmap;}


原创粉丝点击