この質問はよく出てくるようですが、私はこのテーマで多くを読んだことがあります。私の質問はギャラリーからイメージを選択して私はそれを読んで、それを常に肖像画になるように修正したい 私は、カメラを起動し、写真を撮り、Exifデータをチェックして常にその肖像画を確認する方法を実装しましたしかし、これは常に0ギャラリーから選択したイメージの回転をアンドロイドのアクティビティの結果で取得
ExifInterface exifInterface = new ExifInterface(imgFile.getAbsolutePath());
int rotation =
exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL);
int rotationInDegrees = exifToDegrees(rotation);
System.out.println(rotation);
Matrix matrix = new Matrix();
if (rotation != 0f) {
matrix.preRotate(rotationInDegrees);
Bitmap bitmap2 = Bitmap.createBitmap(bitmap, 0,
0, bitmap.getWidth(), bitmap.getHeight(),
matrix,false);
imgView.setImageBitmap(bitmap2);
path = saveToInternalStorage(imageFileName,bitmap2,getApplicationContext());
}
else
path = saveToInternalStorage(imageFileName,bitmap,getApplicationContext());
}
catch (IOException e) {
e.printStackTrace();
}
ExifToDegrees方法
を返しますギャラリーのために私の回転変数を画像を選択するために動作するようには思えませんprivate static int exifToDegrees(int exifOrientation) {
if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_90) {
return 90;
}
else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_180) {
return 180; }
else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_270) {
return 270; }
else if (exifOrientation == 6) {
return 90; }
else if (exifOrientation == 3) {
return 180; }
else if (exifOrientation == 8) {
return 270; }
return 0;
}
私はこれについて多くを読んで述べたように、いくつかのいくつかは、その下の新しい最近のファイルピッカーに言うと、我々は
getAbsolutePath()
、各SDKをチェックすることを使用する必要がありますアンドロイドでそのバグを言いますバージョンと最初の画像を保存することは、私はいくつかは、我々はすべてでのExifを使用する必要はないと言うがない喜びでこれらのすべてをやったし、その
MediaStore.Images.ImageColumns.ORIENTATION
は動作するはずですが、やはりこれは働いていません。
私は私が私のフォルダに
File directory = cw.getDir("SimpleAAC", Context.MODE_PRIVATE);
を画像を保存し、データベースのパスを保存しています(私は私が付与された必要なすべての権限を持っている)ICSからMまでのデバイスをターゲットにしています、私は画像を読み込みますそのフォルダから、私のデータベースからのパスを使用してユニバーサルイメージローダー、 を使用して私はここに、この
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,
"Select A Picture"), PICK_IMAGE_REQUEST);
dialog.dismiss();
でギャラリーを起動する許可を求めるの後には、ギャラリーの私のonActivityResultコードです
if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data !=
null && data.getData() != null) {
Uri uri = data.getData();
BitmapFactory.Options bitmapOptions = new
BitmapFactory.Options();
bitmapOptions.inSampleSize = 4;
InputStream inputStream = null;
try {
inputStream = getContentResolver().openInputStream(uri);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Bitmap scaledBitmap = BitmapFactory.decodeStream(inputStream,
null, bitmapOptions);
String timeStamp = new
SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = timeStamp + ".jpg";
ContextWrapper cw = new ContextWrapper(getApplicationContext());
File directory = cw.getDir("SimpleAAC", Context.MODE_PRIVATE);
File mypath = new File(directory,imageFileName);
FileOutputStream fos = null;
try {
fos = new FileOutputStream(mypath);
scaledBitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
//the relevant parts of this method(setThumbNailImageAndSave) are
// included above
finalPath = setThumbnailImageAndSave(imageView,mypath);
ImageLoader imageLoader = ImageLoader.getInstance();
DisplayImageOptions options = new
DisplayImageOptions.Builder().cacheInMemory(true)
.cacheOnDisc(true).resetViewBeforeLoading(true)
.showImageForEmptyUri(R.drawable.ic_insert_photo_black_24dp)
.showImageOnFail(R.drawable.ic_insert_photo_black_24dp)
.showImageOnLoading(R.drawable.ic_insert_photo_black_24dp).build();
imageLoader.displayImage(finalPath, imageView, options);
System.out.println(finalPath);
}
この質問を締結するために、わかりやすく探していますが、これはバグですか? MediaStore.Images.ImageColumns.ORIENTATIONを使用してこれを回避できますか?それはintent.setAction(intent.ACTION_GET_CONTENT)ですか?それはポストkitkatファイルが変わるのでしょうか?
正直なところ、私は作品を試みるように見えるこれと何の情報を矛盾そんなに読んで、任意およびすべての返信に感謝
なぜあなたは幅と高さを測定しませんか?幅が高さよりも大きければ、あなたはそれが景観をとると仮定することができます。 –
私の友人が返信してくれてありがとう、これはかなりのデバイスでは動作しませんが、間違いなく計画しています。B @Eugene H –
It Worked for me ..!解決した解決策 [解決済み:画像をAndroidでギャラリーから選択したデフォルトの向きに回転する方法(http://stackoverflow.com/questions/40758952/solved-how-to-rotate-image-to-its-defauld-orientation) -selected-from-gallery-in) –