图片上传,部分机型角度不正确问题解决
来源:互联网 发布:windows loader v2.2.2 编辑:程序博客网 时间:2024/05/01 07:29
图片上传,部分机型角度不正确问题解决
前言
现在app大多都有上传图片功能,比如上传图片,发表动态可能还会上传多张图片,那在我做图片上传的时候,出现了部分机型上传图片后,图片的角度是正确的,我的两个测试机小米和华为是没问题的,但是三星的上传后,图片是默认旋转了90°,那这里要讲的就是怎么解决这个问题,在此记录一下,以保证后面再出现类似需求要多考虑一些
解决问题
直接进入正题
当我们上传图片需要做的处理
- 压缩
- 判断角度是否正确
- 如果不角度不对,纠正角度
- 其他(加水印什么的看具体需求)
解决
以下代码块
` /** * 压缩图片,处理某些手机拍照角度旋转的问题 * @param context * @param filePath * @param file * @param q * @return * @throws FileNotFoundException */public static File compressImage(Context context, String filePath, File file, int q) throws FileNotFoundException { Bitmap bm = getSmallBitmap(filePath); int degree = readPictureDegree(filePath); LogUtil.e("fengan", "degree==" + degree); if (degree != 0) {//旋转照片角度 bm = rotateBitmap(bm, degree); } FileOutputStream out = new FileOutputStream(file); bm.compress(Bitmap.CompressFormat.JPEG, q, out); return file;}`/** * 获取图片角度 * @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;} /** * 旋转照片 * @param bitmap * @param degress * @return */public static Bitmap rotateBitmap(Bitmap bitmap, int degress) { if (bitmap != null) { Matrix m = new Matrix(); m.postRotate(degress); bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), m, true); return bitmap; } return bitmap;} /** * 根据路径获得突破并压缩返回bitmap用于显示 * * @return */public static Bitmap getSmallBitmap(String filePath) { final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(filePath, options); // Calculate inSampleSize options.inSampleSize = calculateInSampleSize(options, 480, 800); // Decode bitmap with inSampleSize set options.inJustDecodeBounds = false; return BitmapFactory.decodeFile(filePath, options);}
阅读全文
0 0
- 图片上传,部分机型角度不正确问题解决
- android部分机型选择图片提示错误
- setImageBitmap 图片太大部分机型不显示
- 上传图片方向角度问题
- 创建快捷方式——解决部分机型创建不了或图标文案不正确
- 选择相册图片,修改部分机型错误,4.4以上版本
- UEditor图片上传配置问题解决
- 拍照图片上传竖立问题解决~
- 百度ueditor上传图片(后台配置不正确)
- Android解决部分机型获取不到系统拍照图片,图库图片问题的解决
- ios 调用相机 上传图片到服务器 图片角度问题
- Convirt 时间不正确问题解决
- 使用ueditor上传图片后,图片路径不正确导致图片不能显示
- 百度ueditor struts2图片上传问题解决方案
- 高清图片上传内存问题解决
- java上传带旋转角度的图片旋转问题
- android 下载 ios上传图片的角度显示问题
- 上传图片——前端部分
- HDU 1358 Period(KMP+next数组的运用)
- linux 权限 chmod u+x
- alsa的 snd_pcm_readi 和 snd_pcm_writei
- Javascript性能优化(一)
- bootstrap_fileinput + FastDFS实现图片上传下载功能
- 图片上传,部分机型角度不正确问题解决
- Android 如何定义控件的透明度
- 日系框架之Seasar2之SQL注释大坑-yellowcong
- 第二章 循环结构程序设计
- java查询限定时间内数据总结
- 深度剖析“GCC编译器编译过程”
- Windows窗体应用布局详解
- Javascript模块化编程(一):模块的写法【好文章搬一下】
- swift4.0 新特性