30 June 2016
最近在学习Android的Camera使用方法,通过对Camera的预览使用,谷歌的人脸检测使用,总结了一些经验。
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
//初始化预览界面
private void doOpenCamera() {
mCamera = Camera.open(Camera.CameraInfo.CAMERA_FACING_FRONT);
try {
mCamera.setPreviewDisplay(mSurfaceHolder);
}catch (IOException e){
e.printStackTrace();
}
setCameraDisplayOrientation(this, Camera.CameraInfo.CAMERA_FACING_FRONT,mCamera);
mCamera.startPreview();
}
#错误解决
1.Custom view CustomView is not using the 2- or 3-argument View constructors; XML attributes will not work
You need to override the other 2 constructors of View in CustomView:
public CustomView(Context context) {
super(context);
init(context);
}
public CustomView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
public CustomView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(context);
}
private void init(Context context) {
//do stuff that was in your original constructor...
}
— Kong Jing