2
私はそれについて多くの質問がありますが、私は私の問題の答えを見つけられませんでした。ExifInterfaceは常に0を返しますオリエンテーション
カメラで撮影したり、ストレージからロードしたりできるプロファイル画像を表示しようとしています。
私はExifInterfaceを使用して画像をロードするPicassoの右回転を決定します。
すべての画像のために私のコードの下に= 0
オリエンテーション、非常に単純であり、なぜ私は理解していない:
private void onCaptureImageResult(Intent data) {
Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
thumbnail.compress(Bitmap.CompressFormat.JPEG, 90, bytes);
File destination = new File(Environment.getExternalStorageDirectory(),
System.currentTimeMillis() + ".jpg");
FileOutputStream fo;
try {
destination.createNewFile();
fo = new FileOutputStream(destination);
fo.write(bytes.toByteArray());
fo.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
Picasso.with(getBaseContext()).load("file:" + destination.getPath()).rotate(MyTools.getFileExifRotation("file:" + destination.getPath())).into(avatar);
} catch (IOException e) {
e.printStackTrace();
}
}
@SuppressWarnings("deprecation")
private void onSelectFromGalleryResult(Intent data) {
Bitmap bm=null;
Uri uri=null;
if (data != null) {
try {
bm = MediaStore.Images.Media.getBitmap(getApplicationContext().getContentResolver(), data.getData());
uri=data.getData();
} catch (IOException e) {
e.printStackTrace();
}
}
try {
Picasso.with(getBaseContext()).load("file:" + uri.getPath()).rotate(MyTools.getFileExifRotation("file:" + uri.getPath())).into(avatar);
} catch (IOException e) {
e.printStackTrace();
}
}
public static int getFileExifRotation(String path) throws IOException {
ExifInterface exifInterface = new ExifInterface(path);
int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
return 90;
case ExifInterface.ORIENTATION_ROTATE_180:
return 180;
case ExifInterface.ORIENTATION_ROTATE_270:
return 270;
default:
return 0;
}
}
私はLGのG4の電話でテストします。
私はビットマップを編集しました。私はexif情報を直接取得するコードを変更しました:private void onCaptureImageResult(インテントデータ){ ビットマップサムネイル=(ビットマップ)data.getExtras()。get( "data") ; try { thumbnail = Tools.rotateImageIfRequired(thumbnail、data.getData()); } catch(IOException e){ e.printStackTrace(); } まだ動作していませんExifOrientationは0です。これはアバターを表示するために必要です。 – WhatsUp
あなたのコードを改ざんした理由が不明です。それはまだあなたが始めるビットマップです。そして以前と同じビットマップさえ。ビットマップにはexifや方向情報が含まれていないので意味がありません。代わりにあなたがしなければならないことはすでに言いました。 – greenapps
jpeg画像のexif情報を取得するにはどうすればよいですか?つまり、どうやって画像をjpegで保存し、exifの向きデータを保存することができますか? – viper