使用在layout.xml的surfaceview
<SurfaceView
android:id="@+id/surfaceview"
android:layout_centerHorizontal="true"
android:layout_width="350dp"
android:layout_height="260dp" />
使用下面的活動類代碼
SurfaceView surfaceView;
CameraSource cameraSource;
final TextRecognizer textRecognizer = new TextRecognizer.Builder(getApplicationContext()).build();
cameraSource = new CameraSource.Builder(getApplicationContext(), textRecognizer)
.setFacing(CameraSource.CAMERA_FACING_BACK)
.setAutoFocusEnabled(true)
.build();
surfaceView.getHolder().addCallback(new SurfaceHolder.Callback() {
@Override
public void surfaceCreated(SurfaceHolder surfaceHolder) {
try {
cameraSource.start(surfaceView.getHolder());
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i1, int i2) {
}
@Override
public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
cameraSource.stop();
}
});
textRecognizer.setProcessor(new Detector.Processor<TextBlock>() {
@Override
public void release() {
}
您可以使用本機iOS和Android API創建您自己的相機視圖(例如使用佔位符) - 這裏是p概念屋頂示例應用程序https://github.com/NickIliev/sample-cameraApp –
@NickIliev - 那個github示例不適用於我。有什麼更新?我將在明天發佈git問題日誌 - 如果你正在關注這個問題 – Marko