问题:由于项目竖屏横用,上层开机默认屏幕旋转了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;
}