android Camera相关问题及NV12剪裁旋转
2015-12-21 09:55
477 查看
1、SurfaceView不显示画面,可能是xml设置了背景色,这回遮挡视频画面。
2、如果想保存方形视频,而又不是通过缩放,可以在预览的适合遮挡不需要的画面。录制的适合剪裁一下。
3、因为Camera数据是按横屏给,竖屏的适合,画面会选择90°,StartPreview前设置:mCamera.setDisplayOrientation(90);
4、网上找的几个NV12剪裁及选择代码:
2、如果想保存方形视频,而又不是通过缩放,可以在预览的适合遮挡不需要的画面。录制的适合剪裁一下。
3、因为Camera数据是按横屏给,竖屏的适合,画面会选择90°,StartPreview前设置:mCamera.setDisplayOrientation(90);
4、网上找的几个NV12剪裁及选择代码:
private byte[] rotateYUV420Degree90(byte[] data, int imageWidth, int imageHeight) { final byte [] yuv = new byte[previewWidth*previewHeight*3/2]; // Rotate the Y luma int i = 0; for(int x = 0;x < imageWidth;x++) { for(int y = imageHeight-1;y >= 0;y--) { yuv[i] = data[y*imageWidth+x]; i++; } } // Rotate the U and V color components i = imageWidth*imageHeight*3/2-1; for(int x = imageWidth-1;x > 0;x=x-2) { for(int y = 0;y < imageHeight/2;y++) { yuv[i] = data[(imageWidth*imageHeight)+(y*imageWidth)+x]; i--; yuv[i] = data[(imageWidth*imageHeight)+(y*imageWidth)+(x-1)]; i--; } } return yuv; } private byte[] rotateYUV420Degree180(byte[] data, int imageWidth, int imageHeight) { byte [] yuv = new byte[imageWidth*imageHeight*3/2]; int i = 0; int count = 0; for (i = imageWidth * imageHeight - 1; i >= 0; i--) { yuv[count] = data[i]; count++; } i = imageWidth * imageHeight * 3 / 2 - 1; for (i = imageWidth * imageHeight * 3 / 2 - 1; i >= imageWidth * imageHeight; i -= 2) { yuv[count++] = data[i - 1]; yuv[count++] = data[i]; } return yuv; } private byte[] rotateYUV420Degree270(byte[] data, int imageWidth, int imageHeight) { final byte [] yuv = new byte[previewWidth*previewHeight*3/2]; int wh = 0; int uvHeight = 0; if(imageWidth != 0 || imageHeight != 0) { wh = imageWidth * imageHeight; uvHeight = imageHeight >> 1;//uvHeight = height / 2 } //旋转Y int k = 0; for(int i = 0; i < imageWidth; i++) { int nPos = 0; for(int j = 0; j < imageHeight; j++) { yuv[k] = data[nPos + i]; k++; nPos += imageWidth; } } for(int i = 0; i < imageWidth; i+=2){ int nPos = wh; for(int j = 0; j < uvHeight; j++) { yuv[k] = data[nPos + i]; yuv[k + 1] = data[nPos + i + 1]; k += 2; nPos += imageWidth; } }
}
public byte[] cropYUV420(byte[] data,int imageW,int imageH,int newImageH){ int cropH; int i,j,count,tmp; byte[] yuv = new byte[imageW*newImageH*3/2]; cropH = (imageH - newImageH)/2; count = 0; for(j=cropH;j<cropH+newImageH;j++){ for(i=0;i<imageW;i++){ yuv[count++] = data[j*imageW+i]; } } //Cr Cb tmp = imageH+cropH/2; for(j=tmp;j<tmp + newImageH/2;j++){ for(i=0;i<imageW;i++){ yuv[count++] = data[j*imageW+i]; } } return yuv; }
相关文章推荐
- Android移植 framebuffer
- Android应用Design Support Library完全使用实例
- Android中dp和px之间进行转换
- android中sharedPreferences的用法
- Android 悬浮窗
- android-USB Host and Accessory(附加)
- android 布局中Fragment嵌套Fragment
- Android使用Sensor感应器实现线程中刷新UI创建android测力计的功能
- Android Paint和Color类
- Android轻量级便签应用项目源码
- Android天天数钱游戏源码
- Android基于Sensor感应器获取重力感应加速度的方法
- android错误:Installation error: INSTALL_FAILED_VERSION_DOWNGRADE
- Android IOS WebRTC 音视频开发总结(五五)-- 音视频通讯中的抗丢包与带宽自适应原理
- Android如何制作漂亮的自适布局的键盘
- Java服务器对外提供接口以及Android端向服务器请求数据
- RecyclerView的长按多选功能
- android studio 首字母提示 设置 大小写敏感
- android 录音笔demo!!!(Baseadapter、file、MediaRecorder、AlertDialog)
- Android 性能分析工具dumpsys的使用(自己增加一部分在后面)