我正在构建一个使用相机拍照的应用程序。下面是我做这件事的源代码:
File file = new File(Environment.getExternalStorageDirectory(),
imageFileName);
imageFilePath = file.getPath();
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
//Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
startActivityForResult(intent, ACTIVITY_NATIVE_CAMERA_AQUIRE);
在onActivityResult()
方法中,我使用BitmapFactory.decodeStream()
来拾取图像。
当我在Nexus one上运行我的应用程序时,它运行得很好。但当我在三星Galaxy S或HTC Inspire 4G上运行时,图像的方向不正确。
使用肖像模式拍摄
拍摄后的图像预览-SD卡上的真实图像
采用横向模式的
拍摄后的图像预览-SD卡上的真实图像
发布于 2011-05-25 20:21:28
这里有很多类似的话题和问题。既然你不是在写你自己的相机,我认为它可以归结为:
一些设备在保存之前旋转图像,而另一些设备只是在照片的exif数据中添加方向标签。
我建议检查照片的exif数据,特别是
ExifInterface exif = new ExifInterface(SourceFileName); //Since API Level 5
String exifOrientation = exif.getAttribute(ExifInterface.TAG_ORIENTATION);
由于照片在你的应用程序中显示正确,我不确定问题出在哪里,但这肯定会让你走上正确的道路!
发布于 2012-06-01 13:22:40
我刚刚遇到了同样的问题,并使用此来更正方向:
public void fixOrientation() {
if (mBitmap.getWidth() > mBitmap.getHeight()) {
Matrix matrix = new Matrix();
matrix.postRotate(90);
mBitmap = Bitmap.createBitmap(mBitmap , 0, 0, mBitmap.getWidth(), mBitmap.getHeight(), matrix, true);
}
}
如果位图的宽度大于高度,则返回的图像是横向的,因此我将其旋转90度。
希望它能对其他人解决这个问题有所帮助。
发布于 2013-07-04 18:28:36
需要两件事:
camera.setDisplayOrientation(result);
Camera.Parameters
完成此操作。int mRotation = getCameraDisplayOrientation();Camera.Parameters参数= camera.getParameters();parameters.setRotation(mRotation);//设置旋转保存图片结果(camera.setDisplayOrientation);//设置预览摄像头结果的旋转
希望这能有所帮助。
https://stackoverflow.com/questions/6069122
复制相似问题