android 下载 ios上传图片的角度显示问题

来源:互联网 发布:淘宝的实拍保护 编辑:程序博客网 时间:2024/05/22 04:41

最近做项目时,遇到了android端 显示ios端上传图片的问题 ,图片角度是随着ios端拍照的角度显示的 ,也就是说如果ios端 横着拍照,android端的图片就横着显示,如果ios端竖着拍照,android端的图拍呢就竖着显示, android端显示android端上传的图片没有问题,我想是android系统内部做了处理.鸡精周折,才找到了原来可以获取照片拍照时的角度,

如何获取和改变图片的方向呢,android中提供了一个ExifInterface接口,用于获取图像文件的信息:


public class ImageRotateHelper {/** 从给定的路径载入图片,并指定旋转方向*/public static Bitmap ImageRotateBitmap(Bitmap bm,String imgpath) {int digree = 0;ExifInterface exif = null;try {exif = new ExifInterface(imgpath);} catch (IOException e) {e.printStackTrace();exif = null;}if (exif != null) {// 读取图片中相机方向信息int ori = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,ExifInterface.ORIENTATION_UNDEFINED);// 计算旋转角度switch (ori) {case ExifInterface.ORIENTATION_ROTATE_90://打印出来是6digree = 90;break;case ExifInterface.ORIENTATION_ROTATE_180://打印出来是3digree = 180;break;case ExifInterface.ORIENTATION_ROTATE_270://打印出来是8digree = 270;break;default:digree = 0;break;}}if (digree != 0) {// 旋转图片Matrix m = new Matrix();m.postRotate(digree);bm = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(),bm.getHeight(), m, true);}return bm;}}
通过这个类   就可以将显示方向不正确的图片,正确显示出来,希望能帮到你们 

原创粉丝点击