写真の回転の問題コードにexifInterfaceを使用しています。以下のとおりです。カメラからキャプチャされた画像の向きの問題に直面しています。
- ファイルからビットマップを作成します
Bitmap b = BitmapFactory.decodeFile(imagePath);
- 適切なレベルにスケーリングしてビットマップのサイズを変更します
int width = b.getWidth();
int height = b.getHeight();
int newWidth = 150;
int newHeight = 150;
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
// Bitmap resizedBitmap = Bitmap.createBitmap(b, 0, 0, width, height, matrix, true);
// resizedBitmap.compress(Bitmap.CompressFormat.JPEG, 70, out);
- 画像の向きを処理します
ExifInterface exif = new ExifInterface(imagePath);
String orientation = exif.getAttribute(ExifInterface.TAG_ORIENTATION);
if (orientation.equals(ExifInterface.ORIENTATION_NORMAL)) {
// Do nothing. The original image is fine.
} else if (orientation.equals(ExifInterface.ORIENTATION_ROTATE_90+"")) {
matrix.postRotate(90);
} else if (orientation.equals(ExifInterface.ORIENTATION_ROTATE_180+"")) {
matrix.postRotate(180);
} else if (orientation.equals(ExifInterface.ORIENTATION_ROTATE_270+"")) {
matrix.postRotate(270);
}
- 新しいビットマップを保存します
out = new FileOutputStream(new File("some output file path"));
Bitmap resizedBitmap = Bitmap.createBitmap(b, 0, 0, width, height, matrix, true);
resizedBitmap.compress(Bitmap.CompressFormat.JPEG, 70, out);
このコードは回転の問題を解決するために機能しません。ガイドラインを教えてください。Lgデバイスでは、exifinterfaceは常に0の向きを返し、Samsungデバイスは6と1を返します。
htc、Motorola、samsung、Sony、LGなどのすべてのデバイスでこの問題を修正する方法。
みなさん、ありがとうございました。助けてください。