使用intent我将图像捕获到imageview中,但在设置时它会旋转90或270。如何限制这种旋转?
Intent i=new Intent(MediaStore.ACTION_IMAGE_CAPTURE); i.putExtra(MediaStore.EXTRA_OUTPUT,Uri.parse("file:///"+mProfile_Image));
startActivityForResult(i, 1);
// Set to imageview
mProfileImage.setImageURI(Uri.parse("file:///"+mProfile_Image));
// here imageview is the path
答案 0 :(得分:1)
您无需限制旋转。
尝试以下
Uri imageUri = Uri.parse(path);
String imagePath = path;
int rotate = 0;
// initializing
int dpWidth = 100;
int dpHeight = 100;
try {
getContentResolver().notifyChange(imageUri, null);
File imageFile = new File(imagePath);
ExifInterface exif = new ExifInterface(imageFile.getAbsolutePath());
int orientation = exif.getAttributeInt(
ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL);
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_270:
rotate = 270;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
rotate = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_90:
rotate = 90;
break;
}
} catch (Exception e) {
e.printStackTrace();
}
dpWidth = (int) ((outMetrics.widthPixels / density) * .75);
dpHeight = (int) ((outMetrics.heightPixels / density) * .75);
Matrix matrix = new Matrix();
matrix.postRotate(rotate);
这将有助于您显示正确的图像
修改强>
此代码不用于永久旋转图像。所以每当你想在inmageView中显示图像时,只需旋转并添加。
修改1
使用此功能在imageview中设置图像
Bitmap bm = BitmapFactory.decodeFile(path);
Bitmap bm = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(),
matrix, true);
imageView.setImageBitmap(bm);
答案 1 :(得分:0)
将您的活动方向设置为肖像并试一试。
<activity
android:name="YourActivityName"
android:screenOrientation="portrait">
</activity>