android关于手机拍照图片旋转问题

相信大家在项目中经常要掉系统的拍照功能吧,但是我发现了一个问题,三星手机在调用系统摄像机的时候拍出的图片居然呗旋转过!遂网上找了一大把资料,但是众说纷坛,很多都没有时间解决问题。最后自己不断结合摸索,终于解决了旋转问题不多说,直接上代码:

int rotate =   change.readPictureDegree(mOutPutFileUri);  //三星手机前置为8,旋转270度。后置为6旋转90度
 if (rotate == 90 || rotate == 270) { 
	System.out.println("三星手机");
	Bitmap bitmap = BitmapFactory.decodeFile(mOutPutFileUri);//根据Path读取资源图片 
	int width = bitmap.getWidth()/2;
	int height = bitmap.getHeight()/2;
	System.out.println("图片的宽为:"+bitmap.getWidth()+"\n"+"图片的高为:"+bitmap.getHeight());
	 if (rotate == 90) {
		 m.setRotate(90); // 旋转angle度									
	 }else{
			m.setRotate(270); // 旋转angle度									
		 }
   bitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height,m, true);// 从新生成图片

/**
		 * 读取图片属性:旋转的角度
		 * @param path 图片绝对路径
		 * @return degree旋转的角度
		 * 三星手机前置为8,旋转270度。后置为6旋转90度
		 */
	    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);
	                System.out.println("图片的旋转角度是=="+orientation);
	                switch (orientation) {
	                case 6:
	                        degree = 90;
	                        break;
	                case ExifInterface.ORIENTATION_ROTATE_180:
	                        degree = 180;
	                        break;
	                case 8:
	                        degree = 270;
	                        break;
	                }
	        } catch (IOException e) {
	                e.printStackTrace();
	        }
	        return degree;
	    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值