捕获的照片显示方向正在改变机器人 [英] Captured Photo orientation is changing in android
问题描述
我'上点击一个按钮,打开相机应用。和显示拍摄的照片中下一个活动。但所捕获的照片旋转90度。当我在我拍摄后的视图显示图像,它的方向是永远的风景。为什么照片没有显示在画像作为当照片拍摄在纵向模式是?
按钮的onClick:
意向书我=新的意图(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT,Uri.fromFile(新文件(APP_DIR +/ latest.png)));
startActivityForResult(ⅰ,CAPTURE_PHOTO_CONSTANT);
里面onActvityresult:
BMP = BitmapFactory.de codeFILE(APP_DIR +/ latest.png);
startActivity(新意图(这一点,DisplayActivity.class));
显示拍摄的照片:
photoViewRelativeLayout.setBackgroundDrawable(新BitmapDrawable(getResources(),CaptureActivity.bmp));
我有同样的问题大多与三星handsets.Apparently三星手机设置的EXIF方向标签,而不是使用BitmapFactory不旋转个人pixels.Reading位图支持此tag.What我找到了解决这个问题是在activity.Which检查具有URI从相机相关联的捕捉到的图像的取向onActivityResult方法使用ExifInterface
INT旋转= 0;
尝试 {
getContentResolver()有NotifyChange(imageUri,空)。
文件镜像文件=新的文件(的ImagePath);
ExifInterface EXIF =新ExifInterface(
imageFile.getAbsolutePath());
INT方向= exif.getAttributeInt(
ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL);
开关(方向){
案例ExifInterface.ORIENTATION_ROTATE_270:
旋转= 270;
打破;
案例ExifInterface.ORIENTATION_ROTATE_180:
旋转= 180;
打破;
案例ExifInterface.ORIENTATION_ROTATE_90:
旋转= 90;
打破;
}
Log.v(Common.TAG,的Exif方向:+方向);
}赶上(例外五){
e.printStackTrace();
}
/ ******图像旋转**** /
字模=新的Matrix();
matrix.postRotate(方向);
位图裁剪= Bitmap.createBitmap(缩放,X,Y,宽度,高度,矩阵,真);
I'am opening camera app on click of a button. And displaying the captured photo in next activity. But the captured photo is rotating by 90 degrees. When I display the image in a view after I capture it, it's orientation is always landscape. Why is the photo not being shown in portrait as is when the photo is taken in portrait mode?
onClick of a button :
Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(APP_DIR+"/latest.png")));
startActivityForResult(i, CAPTURE_PHOTO_CONSTANT);
Inside onActvityresult:
bmp = BitmapFactory.decodeFile(APP_DIR+"/latest.png");
startActivity(new Intent(this, DisplayActivity.class));
Displaying captured photo:
photoViewRelativeLayout.setBackgroundDrawable(new BitmapDrawable(getResources(), CaptureActivity.bmp));
I had the same problem mostly with the Samsung handsets.Apparently Samsung phones set the EXIF orientation tag, rather than rotating individual pixels.Reading the Bitmap using BitmapFactory does not support this tag.What i found the solution to this problem was using ExifInterface in onActivityResult method of the activity.Which checks for orientation associated with URI of the captured image from the camera.
int rotate = 0;
try {
getContentResolver().notifyChange(imageUri, null);
File imageFile = new File(imagePath);
ExifInterface exif = new ExifInterface(
imageFile.getAbsolutePath());
int orientation = exif.getAttributeInt(
ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL);
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_270:
rotate = 270;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
rotate = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_90:
rotate = 90;
break;
}
Log.v(Common.TAG, "Exif orientation: " + orientation);
} catch (Exception e) {
e.printStackTrace();
}
/****** Image rotation ****/
Matrix matrix = new Matrix();
matrix.postRotate(orientation);
Bitmap cropped = Bitmap.createBitmap(scaled, x, y, width, height, matrix, true);
这篇关于捕获的照片显示方向正在改变机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!