【发布时间】:2014-01-06 11:13:43
【问题描述】:
从图库中选择图像后,我想强制以纵向显示图像。我正在使用下面的代码。
findViewById(R.id.btn_open_galllery).setOnClickListener(
new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent selectPictureIntent = new Intent(
Intent.ACTION_PICK);
selectPictureIntent.setType("image/*");
startActivityForResult(selectPictureIntent, 1212);
}
});
//关于活动结果
Uri selectedImageUri = data.getData();
Bitmap bitmap = null;
try {
bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), selectedImageUri);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
File file = new File(selectedImageUri.getPath());
try {
ExifInterface exif = new ExifInterface(file.getAbsolutePath());
orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);
Log.e("Orientation", ""+orientation);
Matrix matrix = new Matrix();
matrix.postRotate(90);
Bitmap rotatedBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
iv.setImageBitmap(rotatedBitmap);
} catch (IOException e1) {
e1.printStackTrace();
}
// 这里我得到了图像的每次旋转,但如果图像处于横向模式,我只想要图像的纵向模式。
【问题讨论】:
-
将orientation 属性添加到您的manifest 文件中以进行该特定活动
-
@Swap-IOS-Android 没有。如果它处于横向模式,我只想旋转图像。谢谢
标签: android orientation