三星手机照片读取,图片位置不对问题。

fa2002 2016-05-24 11:25:28
我们的相册控件不知道为什么,在三星手机上看到的部分图片都是倒着的。

但用三星自己的相册看是正的。

我们自己加旋转,图片多了又会导致oom.
这个问题如何解决会更好?还望高人指教
...全文
643 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
fa2002 2016-05-24
  • 打赏
  • 举报
回复
自己顶!!!!!!
fa2002 2016-05-24
  • 打赏
  • 举报
回复
没那么简单啊,旋转多了会oom
蒲锦_up 2016-05-24
  • 打赏
  • 举报
回复
因为图片旋转了90度 你获取图片的旋转角度,转回来就行了
筱蒙 2016-05-24
  • 打赏
  • 举报
回复
当时我们用三星手机照出来相片也是旋转的,用得这个方法,不知道和你们用的一样不一样 ,我先贴出来你看看。 /** * 图片按比例大小压缩方法(根据路径获取图片并压缩): * * @param srcPath * @return */ public static byte[] getImageBytes(String srcPath) { BitmapFactory.Options newOpts = new BitmapFactory.Options(); // 开始读入图片,此时把options.inJustDecodeBounds 设回true了 newOpts.inJustDecodeBounds = true; Bitmap bitmap = BitmapFactory.decodeFile(srcPath, newOpts);// 此时返回bm为空 newOpts.inJustDecodeBounds = false; int w = newOpts.outWidth; int h = newOpts.outHeight; // 设置固定分辨率,所以高和宽我们设置为 float hh = 800f;// 这里设置高度为800f float ww = 600f;// 这里设置宽度为480f // 缩放比。由于是固定比例缩放,只用高或者宽其中一个数据进行计算即可 int be = 1;// be=1表示不缩放 if (w > h && w > ww) {// 如果宽度大的话根据宽度固定大小缩放 be = (int) (newOpts.outWidth / ww); } else if (w < h && h > hh) {// 如果高度高的话根据宽度固定大小缩放 be = (int) (newOpts.outHeight / hh); } else if (w == h) {// 如果高度高的话根据宽度固定大小缩放 be = (int) (newOpts.outHeight / hh); } if (be <= 0) be = 1; newOpts.inSampleSize = be;// 设置缩放比例 // 重新读入图片,注意此时已经把options.inJustDecodeBounds 设回false了 bitmap = BitmapFactory.decodeFile(srcPath, newOpts); int degree = readPictureDegree(srcPath); Bitmap newBitmap = rotatingImageView(degree, bitmap); ByteArrayOutputStream baos = new ByteArrayOutputStream(); newBitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos); if (newBitmap != null) { newBitmap.recycle(); System.gc(); } return baos.toByteArray();// 压缩好比例大小后再进行质量压缩 } /** * 获取图片旋转的角度 * * @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 angle 图片旋转的角度 * * @param bitmap */ public static Bitmap rotatingImageView(int angle, Bitmap bitmap) { if (angle == 0) return bitmap; // 旋转图片 动作 Matrix matrix = new Matrix(); matrix.postRotate(angle); // 创建新的图片 Bitmap resizedBitmap = null; if (bitmap != null) { resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); } return resizedBitmap; }

80,492

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧