Android 有些上传到图像视图的图像正在旋转,有些则没有
我正在尝试上传图片以适应图像视图。但有些图像正在正确上传,有些图像正在旋转上传。检查此项 您需要获取图像位图,获取方向值并将图像旋转到正确的角度Android 有些上传到图像视图的图像正在旋转,有些则没有,android,android-layout,Android,Android Layout,我正在尝试上传图片以适应图像视图。但有些图像正在正确上传,有些图像正在旋转上传。检查此项 您需要获取图像位图,获取方向值并将图像旋转到正确的角度 ExifInterface exif; try { exif = new ExifInterface(photoPath); } catch (IOException e) { e.printStackTrace(); exif
ExifInterface exif;
try {
exif = new ExifInterface(photoPath);
}
catch (IOException e) {
e.printStackTrace();
exif = null;
}
if(exif!=null){
orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);
}
//get Bitmap
Bitmpam bitm = ..... ;//uploaded file
if(orientation==8){
Matrix matrix = new Matrix();
matrix.postRotate(270);
bitm = Bitmap.createBitmap(bitm, 0, 0, bitm.getWidth(), bitm.getHeight(), matrix, true);
}
if(orientation==6){
Matrix matrix = new Matrix();
matrix.postRotate(90);
bitm = Bitmap.createBitmap(bitm, 0, 0, bitm.getWidth(), bitm.getHeight(),matrix,true);
}
if(orientation==3){
Matrix matrix = new Matrix();
matrix.postRotate(180);
bitm = Bitmap.createBitmap(bitm, 0, 0, bitm.getWidth(), bitm.getHeight(),matrix,true);
}
希望对您有所帮助检查此项
您需要获取图像位图,获取方向值并将图像旋转到正确的角度
ExifInterface exif;
try {
exif = new ExifInterface(photoPath);
}
catch (IOException e) {
e.printStackTrace();
exif = null;
}
if(exif!=null){
orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);
}
//get Bitmap
Bitmpam bitm = ..... ;//uploaded file
if(orientation==8){
Matrix matrix = new Matrix();
matrix.postRotate(270);
bitm = Bitmap.createBitmap(bitm, 0, 0, bitm.getWidth(), bitm.getHeight(), matrix, true);
}
if(orientation==6){
Matrix matrix = new Matrix();
matrix.postRotate(90);
bitm = Bitmap.createBitmap(bitm, 0, 0, bitm.getWidth(), bitm.getHeight(),matrix,true);
}
if(orientation==3){
Matrix matrix = new Matrix();
matrix.postRotate(180);
bitm = Bitmap.createBitmap(bitm, 0, 0, bitm.getWidth(), bitm.getHeight(),matrix,true);
}
希望能有帮助