私はMicrosoftのprojectOxford EmotionApiの画像自動回転コードに適応しようとしています。デバイスカメラによって撮影された各画像は、その角度について分析され、次に感情APIによって分析される正しい風景ビューに回転される。ImageURI/ContentResolverを使用せずにビットマップを回転させますか?
私の質問は、ビットマップを引数として使用するために、以下のコードをどのように変更すればよいですか?この場合、コンテンツリゾルバとExitInterfaceの役割については完全に失われています。どんな助けでも大歓迎です。
private static int getImageRotationAngle(
Uri imageUri, ContentResolver contentResolver) throws IOException {
int angle = 0;
Cursor cursor = contentResolver.query(imageUri,
new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null);
if (cursor != null) {
if (cursor.getCount() == 1) {
cursor.moveToFirst();
angle = cursor.getInt(0);
}
cursor.close();
} else {
ExifInterface exif = new ExifInterface(imageUri.getPath());
int orientation = exif.getAttributeInt(
ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_270:
angle = 270;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
angle = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_90:
angle = 90;
break;
default:
break;
}
}
return angle;
}
// Rotate the original bitmap according to the given orientation angle
private static Bitmap rotateBitmap(Bitmap bitmap, int angle) {
// If the rotate angle is 0, then return the original image, else return the rotated image
if (angle != 0) {
Matrix matrix = new Matrix();
matrix.postRotate(angle);
return Bitmap.createBitmap(
bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
} else {
return bitmap;
}
}
ご了承ください。徹底した説明をお願いします。ビットマップの回転に関する推奨事項はありますか? –
@ A.Xu:質問の 'rotateBitmap()'メソッドは、ビットマップを回転させます。 EXIFヘッダー全体の背後にあるポイントは、JPEGを回転するかどうかを決定することです。 – CommonsWare