Android camera的使用

本文探讨了Android相机预览参数的设定,包括实际图像大小配置,并引用了多个参考资料。针对系统返回照片的旋转问题,提出了两种处理方案:一种是对未旋转照片进行后期处理,另一种是处理已旋转的正常照片。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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就可以用了   注意  这个是根据你手机的重力感应进行旋转的  所以当你的手机角度比较刁钻  会发现有些小问题  自己看看吧  讲不清楚
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值