由于前面的博文中忽略了点内容,所以在这里补上,下面内容就是解决拍照或者选择图片显示的时候图片旋转了90度或者其他度数问题,以便照片可以正面显示:具体如下:
首先直接看上面博文下的拍完照或者选完图后处理部分:
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
-
- switch (resultCode) {
- case 1:
- if (data != null) {
-
- Uri mImageCaptureUri = data.getData();
-
- if (mImageCaptureUri != null) {
- setImage(mImageCaptureUri);
- }
- }
- break;
- default:
- break;
-
- }
- }
第二:处理90度问题并显示:
- private void setImage(Uri mImageCaptureUri) {
-
-
-
-
- ContentResolver cr = this.getContentResolver();
- Cursor cursor = cr.query(mImageCaptureUri, null, null, null, null);
- if (cursor != null) {
- cursor.moveToFirst();
- String filePath = cursor.getString(cursor.getColumnIndex("_data"));
- String orientation = cursor.getString(cursor
- .getColumnIndex("orientation"));
- cursor.close();
- if (filePath != null) {
- Bitmap bitmap = BitmapFactory.decodeFile(filePath);
- int angle = 0;
- if (orientation != null && !"".equals(orientation)) {
- angle = Integer.parseInt(orientation);
- }
- if (angle != 0) {
-
- Matrix m = new Matrix();
- int width = bitmap.getWidth();
- int height = bitmap.getHeight();
- m.setRotate(angle);
- bitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height,
- m, true);
-
- }
- photo.setImageBitmap(bitmap);
- }
- }
- }
OK完成,需要拍照和选择图片功能的部分请看http://104zz.iteye.com/blog/1687662
android 选择图片或拍照时旋转了90度问题
原文:http://www.cnblogs.com/hudabing/p/4766391.html