wifi扫码问题,android 12 MTK 解决屏幕默认ROTATION_270或者旋转ROTATION_180,设置wifi扫码不能识别的问题

文章描述了一个在设备旋转270度后,WiFi二维码扫描功能失效的问题。通过添加和修改代码,实现了对从Camera获取的数据流进行旋转处理,特别是针对YUV420格式的图像,以确保在不同屏幕旋转状态下能正确识别二维码。当屏幕旋转为180或270度时,应用了特定的旋转算法来调整图像数据。
摘要由CSDN通过智能技术生成

问题:由于项目竖屏横用,上层开机默认屏幕旋转了270之后,设置wifi扫码出现了不能识别的问题,打开屏幕自动旋转后,只有屏幕角度是Surface.ROTATION_0和Surface.ROTATION_90是可以的扫码的,所以旋转下从Camera截取获取的数据流

源码路径:vendor/mediatek/proprietary/packages/apps/MtkSettings/src/com/android/settings/wifi/qrcode/QrCamera.java

    private QrYuvLuminanceSource getFrameImage(byte[] imageData) {
        final Rect frame = mScannerCallback.getFramePosition(mPreviewSize, mCameraOrientation);
        //modify start
        final QrYuvLuminanceSource image = new QrYuvLuminanceSource(rotateByte(imageData),
                mPreviewSize.getWidth(), mPreviewSize.getHeight());
        //modify end
        return (QrYuvLuminanceSource)
                image.crop(frame.left, frame.top, frame.width(), frame.height());
    }

添加下面两个方法

    private byte[] rotateByte(byte[] data) {
        final int rotation = mWindowManager.getDefaultDisplay().getRotation();
        Log.d(TAG, "[rotateByte] rotation " + rotation);
        if (rotation== Surface.ROTATION_180 || rotation == Surface.ROTATION_270){
            return rotateYUV420Degree180(data,mPreviewSize.getWidth(),mPreviewSize.getHeight());
        }
        return data;
    }
    private byte[] rotateYUV420Degree180(byte[] data, int imageWidth, int imageHeight) {
        byte[] yuv = new byte[imageWidth * imageHeight * 3 / 2];
        int i;
        int count = 0;
        for (i = imageWidth * imageHeight - 1; i >= 0; i--) {
            yuv[count] = data[i];
            count++;
        }
        for (i = imageWidth * imageHeight * 3 / 2 - 1; i >= imageWidth
                * imageHeight; i -= 2) {
            yuv[count++] = data[i - 1];
            yuv[count++] = data[i];
        }
        return yuv;
    }
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值