Android相机预览旋转
根据Android开发者网站: 在安卓2.2之后就有了这个功能 “设置显示方向” 调整摄影机预览旋转的步骤 另外,根据Android开发者网站,我们可以找到以下源代码Android相机预览旋转,android,orientation,android-camera,Android,Orientation,Android Camera,根据Android开发者网站: 在安卓2.2之后就有了这个功能 “设置显示方向” 调整摄影机预览旋转的步骤 另外,根据Android开发者网站,我们可以找到以下源代码 android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo(); android.hardware.Camera.getCameraInfo(cameraId, info); int rot
android.hardware.Camera.CameraInfo info =
new android.hardware.Camera.CameraInfo();
android.hardware.Camera.getCameraInfo(cameraId, info);
int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
int degrees = 0 ;
switch ( rotation ) {
case Surface.ROTATION_0 : degrees = 0 ; break ;
case Surface.ROTATION_90 : degrees = 90 ; break ;
case Surface.ROTATION_180 : degrees = 180 ; break ;
case Surface.ROTATION_270 : degrees = 270 ; break ;
}
int result ;
if ( info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
result = ( info.orientation + degrees ) % 360 ;
result = ( 360 - result ) % 360 ; // compensate the mirror
} else { // back-facing
result = ( info.orientation - degrees + 360 ) % 360 ;
}
但是,我不能使用某些设备。
如三星Galaxy Y S5360、S5660、YP-G1、YP-G70等
只是机器的一部分不工作,Galaxy Nexus、SII或一些高端设备,工作正常
setDisplayOrientation不支持,或者设备固件未准备好
所有设备均为安卓2.3.1或以上版本
帮助。尝试将相机视图的xml方向设置为横向。设置相机方向显示的问题在这些设备的操作系统版本(基本上是姜饼)上不起作用,但对于上面的设备,它可以正常工作 我在这些设备上也尝试过这种方法。横向模式很好,但纵向模式有问题。如果要强制拍摄人像,只需将相机方向强制为90度即可 通过这个
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
camera.setDisplayOrientation(90);
}
以及post在显示或保存图片之前是否旋转了图片
在
希望这有帮助我的银河Y也面临同样的问题。你发现了什么吗?我想知道至少setDisplayOrientation是否成功,如果不成功,将其锁定到横向。最后,未解决。只需将相机表面活动设置为水平视图。是否有人拥有发生此错误的设备列表?任何帮助都将不胜感激。这不是一个真正有用的答案,如果OP不想看到风景,他不会问如何得到肖像。@Shirkrin这个答案一开始看起来很奇怪。但事实是,在某些设备中,相机的预览是固定在横向的。如果将相机预览的xml调整为横向,它将适合所有设备。接下来要做的是使用矩阵旋转相机拍摄的照片。
PictureCallback myPictureCallback_JPG = new PictureCallback(){
public void onPictureTaken(byte[] arg0, Camera arg1) {
Bitmap bitmapPicture= BitmapFactory.decodeByteArray(arg0, 0, arg0.length);
Matrix matrix = new Matrix();
matrix.postRotate(90);
int height=bitmapPicture.getHeight();
int width=bitmapPicture.getWidth();
Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmapPicture,height,width, true);
Bitmap rotatedBitmap = Bitmap.createBitmap(scaledBitmap , 0, 0, scaledBitmap.getWidth(), scaledBitmap.getHeight(), matrix, true);
}