Android camera预览参数以及实际图像大小设置
参考
http://www.cnblogs.com/skyseraph/archive/2012/03/26/2418665.html
http://blog.csdn.net/yanzi1225627/article/details/7738736
https://blog.csdn.net/zhi184816/article/details/52415327
关于 旋转返回的图片的角度 有两种方式
方式一:系统返回的是未旋转的照片(不正常的照片)
我们拿到照照片后对他进行处理
Matrix mMatrix = new Matrix();
mMatrix.postRotate(270);//这个角度是根据不同的手机获取的
Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), mMatrix, false);
方式二:系统返回的是已经旋转的照片(正常的照片)我们拿到后直接处理即可
public class IOrientationEventListener extends OrientationEventListener {
public IOrientationEventListener(Context context) {
super(context);
}
@Override
public void onOrientationChanged(int orientation) {
if (ORIENTATION_UNKNOWN == orientation) {
return;
}
Camera.CameraInfo info = new Camera.CameraInfo();
Camera.getCameraInfo(1, info);//注意
orientation = (orientation + 45) / 90 * 90;
int rotation = 0;
if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
rotation = (info.orientation - orientation + 360) % 360;
} else {
rotation = (info.orientation + orientation) % 360;
}
Log.e("TAG", "orientation: " + orientation);
if (null != mCamera) {
Camera.Parameters parameters = mCamera.getParameters();
parameters.setRotation(rotation);//设置截取后旋转的图片的方向
mCamera.setParameters(parameters);
}
}
}
再oncreate中new出来
orientationEventListener = new IOrientationEventListener(this);
//再holder中 进行设置 标红的两句话
//实现SurfaceHolder.Callback接口
mHolder.addCallback(new SurfaceHolder.Callback() {
@Override
public void surfaceCreated(SurfaceHolder holder) {
orientationEventListener.enable();
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
orientationEventListener.disable();
}
});
//这样得到的后的图片就是 已经选装好的 我们不需要再进行旋转处理 直接转换成bitmap就可以用了 注意 这个是根据你手机的重力感应进行旋转的 所以当你的手机角度比较刁钻 会发现有些小问题 自己看看吧 讲不清楚