@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Bitmap mBitmap ;
if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK) {
String _path = Environment.getExternalStorageDirectory() + File.separator + "TakenFromCamera.jpg"+time;
mBitmap = BitmapFactory.decodeFile(_path);
ExifInterface exif = null;
try {
exif = new ExifInterface(_path);
} catch (IOException e) {
e.printStackTrace();
}
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_UNDEFINED);
textView.setText(" ");
if(mBitmap.getHeight() < mImageView.getHeight())
mBitmap = RotateBitmap(mBitmap, ExifInterface.ORIENTATION_ROTATE_90);
else
mBitmap = RotateBitmap(mBitmap,orientation);
mImageView.setImageBitmap(mBitmap);
}
else if(requestCode == GALLERY_REQUEST && resultCode == Activity.RESULT_OK)
{
textView.setText(" ");
Uri selectedImage = data.getData();
try{
mBitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), selectedImage);
} catch (IOException e) {
mBitmap= null;
e.printStackTrace();
}
ExifInterface exif = null;
try {
exif = new ExifInterface(selectedImage.getPath());
} catch (IOException e) {
e.printStackTrace();
}
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_UNDEFINED);
RotateBitmap(mBitmap,orientation);
mImageView.setImageBitmap(mBitmap);
}
public Bitmap RotateBitmap(Bitmap bitmap, int orientation) {
Matrix matrix = new Matrix();
switch (orientation) {
case ExifInterface.ORIENTATION_NORMAL:
return bitmap;
case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
matrix.setScale(-1, 1);
break;
case ExifInterface.ORIENTATION_ROTATE_180:
matrix.setRotate(180);
break;
case ExifInterface.ORIENTATION_FLIP_VERTICAL:
matrix.setRotate(180);
matrix.postScale(-1, 1);
break;
case ExifInterface.ORIENTATION_TRANSPOSE:
matrix.setRotate(90);
matrix.postScale(-1, 1);
break;
case ExifInterface.ORIENTATION_ROTATE_90:
matrix.setRotate(90);
break;
case ExifInterface.ORIENTATION_TRANSVERSE:
matrix.setRotate(-90);
matrix.postScale(-1, 1);
break;
case ExifInterface.ORIENTATION_ROTATE_270:
matrix.setRotate(-90);
break;
default:
return bitmap;
}
try{
Bitmap bmRotated = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
return bmRotated;
}
catch (OutOfMemoryError e) {
textView.setText(e.getMessage());
return null;
}
}
Скажите пожалуйста, как узнать занимает ли Bitmap всю площадь ImageView Хочу в зависимости от ориентации картинки поворачивать её пока она не займёт всю площадь ImageView
Метод RotateBitmap не помогает
Продвижение своими сайтами как стратегия роста и независимости