人脸识别-1像素方案

public class FaceServiceextends Service {

/**

* 相机预览显示的控件,可为SurfaceView或TextureView

*/

    private ViewpreviewView;

    @Override

    public IBinderonBind(Intent intent) {

return null;

    }

@Override

    public void onCreate() {

super.onCreate();

    }

@Override

    public int onStartCommand(Intent intent, int flags, int startId) {

getSurfaceView();

        RegisterAndRecognize.getInstance().onCreate(previewView);

        return super.onStartCommand(intent, flags, startId);

    }

private void getSurfaceView() {

previewView =new TextureView(BaseApp.getAppContext());

        WindowManager wm = (WindowManager)BaseApp.getAppContext().getSystemService(BaseApp.getAppContext().WINDOW_SERVICE);

        WindowManager.LayoutParams params =new WindowManager.LayoutParams(1, 1,

                WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,

                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |

WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,

                PixelFormat.TRANSPARENT);

        params.gravity = Gravity.TOP | Gravity.RIGHT;

        params.alpha = PixelFormat.TRANSPARENT;

        params.x = params.y = BaseApp.getAppContext().getResources().getDimensionPixelOffset(

R.dimen.preview_surface_offset);

        wm.addView(previewView, params);

    }

@Override

    public void onDestroy() {

super.onDestroy();

        RegisterAndRecognize.getInstance().onDestroy();

    }

}

你可能感兴趣的:(人脸识别-1像素方案)