Когда я пытаюсь создать кадр сканера, например, [] используя холст для захвата документов, камера останавливается, а фон превращается в черный, и отображается только холст.
Также пробовал просмотр текстуры с помощью camera2 api, но стал белым экранная камера останавливает рендеринг, и видна только рамка холста
Если вы можете оказать мне какую-либо помощь, в основном для просмотра текстур, а также, что может быть лучше
public class CameraActivity extends AppCompatActivity{
TextView testView;
Camera camera;
SurfaceView surfaceView;
SurfaceHolder surfaceHolder;
private RenderThread mThread;
Camera.PictureCallback rawCallback;
Camera.ShutterCallback shutterCallback;
Camera.PictureCallback jpegCallback;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_camera);
surfaceView = findViewById(R.id.surfaceView);
assert surfaceView != null;
surfaceView.getHolder().addCallback(new SurfaceHolder.Callback() {
@Override
public void surfaceCreated(SurfaceHolder holder) {
surfaceHolder = holder;
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
try {
// open the camera
camera = Camera.open();
} catch (RuntimeException e) {
// check for exceptions
System.err.println(e);
return;
}
Camera.Parameters param;
param = camera.getParameters();
param.setPreviewSize(352, 288);
camera.setParameters(param);
try {
camera.setPreviewDisplay(surfaceHolder);
camera.startPreview();
} catch (Exception e) {
System.err.println(e);
return;
}
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
refreshCamera();
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
camera.stopPreview();
camera.release();
camera = null;
}
});
jpegCallback = new Camera.PictureCallback() {
public void onPictureTaken(byte[] data, Camera camera) {
FileOutputStream outStream = null;
try {
outStream = new FileOutputStream(String.format("/sdcard/%d.jpg", System.currentTimeMillis()));
outStream.write(data);
outStream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
}
Toast.makeText(getApplicationContext(), "Picture Saved", Toast.LENGTH_SHORT).show();
refreshCamera();
}
};
}
public void captureImage(View v) throws IOException {
//take the picture
camera.takePicture(null, null, jpegCallback);
}
public void refreshCamera() {
if (surfaceHolder.getSurface() == null) {
// preview surface does not exist
return;
}
try {
camera.stopPreview();
} catch (Exception e) {
}
try {
camera.setPreviewDisplay(surfaceHolder);
camera.startPreview();
} catch (Exception e) {
e.printStackTrace();
}
}
private class RenderThread extends Thread {
private volatile boolean mRunning = true;
@Override
public void run() {
Paint mPaint = new Paint();
System.out.println("Running canvas ...............................");
final Canvas canvas = surfaceHolder.lockCanvas();
try {
if(canvas != null) {
canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setColor(Color.BLUE);
mPaint.setStrokeWidth(10);
Path path = new Path();
canvas.drawLine(250, 250, 400, 250, mPaint);
canvas.drawLine(255, 250, 255, 400, mPaint);
canvas.drawLine(750, 250, 900, 250, mPaint);
canvas.drawLine(895, 250, 895, 400, mPaint);
canvas.drawLine(250, 900, 400, 900, mPaint);
canvas.drawLine(255, 900 - 150, 255, 900, mPaint);
canvas.drawLine(750, 900, 900, 900, mPaint);
canvas.drawLine(895, 900 - 150, 895, 900, mPaint);
canvas.drawPath(path, mPaint);
}
} finally {
surfaceHolder.unlockCanvasAndPost(canvas);
}
}
public void stopRendering() {
interrupt();
mRunning = false;
}
}}