Uri selectedImage = outputFileUri; InputStream imageStream =getContentResolver().openInputStream(selectedImage); try { BitmapFactory.Options bounds = new BitmapFactory.Options(); bounds.inJustDecodeBounds=true; BitmapFactory.decodeFile(Common.getRealPathFromURI(selectedImage, AddStoreActivity.this), bounds); BitmapFactory.Options opts = new BitmapFactory.Options(); Bitmap bm = BitmapFactory.decodeFile(Common.getRealPathFromURI(selectedImage, AddStoreActivity.this), opts); ExifInterface exif = new ExifInterface(Common.getRealPathFromURI(selectedImage, AddStoreActivity.this)); String orientString = exif.getAttribute(ExifInterface.TAG_ORIENTATION); int orientation = orientString != null ? Integer.parseInt(orientString) : ExifInterface.ORIENTATION_NORMAL; int rotationAngle = 0; if (orientation == ExifInterface.ORIENTATION_ROTATE_90) rotationAngle = 90; if (orientation == ExifInterface.ORIENTATION_ROTATE_180) rotationAngle = 180; if (orientation == ExifInterface.ORIENTATION_ROTATE_270) rotationAngle = 270; Matrix matrix = new Matrix(); matrix.setRotate(rotationAngle, (float) bm.getWidth() / 2, (float) bm.getHeight() / 2); Bitmap rotatedBitmap = Bitmap.createBitmap(bm, 0, 0, bounds.outWidth, bounds.outHeight, matrix, true); bitmap2 = rotatedBitmap;//BitmapFactory.decodeStream(imageStream); } catch(Exception ef) { bitmap2 = BitmapFactory.decodeStream(imageStream); }
非常简单,在我的Android应用程序中,我打开相机..并以纵向模式拍照。我把图片重新旋转了。我怎么能解决这个问题?我所做的上述工作没有任何影响。
答案 0 :(得分:0)
尝试替换此代码
matrix.postRotate(rotationAngle);
Bitmap rotatedBitmap = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrix, true);
用这个
(\b(serial|sheet))+(\s(number|code|no))+?\b