Здравствуйте, нужна Ваша помощь.
Для решения моей задачи, мне нужно 2 SurfaceView: 1 для того чтобы брать с него и обрабатывать кадры с камеры, второй для того чтобы отрисовывать полученные данные. Так вот, при запросе Canvas функция lockCanvas возвращает null.
private SurfaceView sv;
private SurfaceView svfd; // Surface view for drawing
private SurfaceHolder holder;
private SurfaceHolder holderFD; // Holder for drawing on Surface View
private HolderCallback holderCallback;
private Camera camera;
...
private Paint paint;
private final PreviewCallback previewCallback;
final int CAMERA_ID = 0;
final boolean FULL_SCREEN = true;
private int ocr_count = 0; // TODO Delete after tests
...
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
mLang = intent.getStringExtra("lang");
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.realtime);
sv = (SurfaceView) findViewById(R.id.surfaceView);
svfd = (SurfaceView) findViewById(R.id.surfaceViewForDrawing);
svfd.setZOrderOnTop(true);
holder = sv.getHolder();
holderFD = svfd.getHolder();
holderCallback = new HolderCallback(this, this);
holder.addCallback(holderCallback);
handler = new RealTimeHandler(this, camera, mLang);
previewCallback.setHandler(handler);
paint = new Paint();
}
...
public void drawFounded(OcrDB OcrResult){
if(OcrResult!=null){
Canvas canvas = holderFD.lockCanvas(); // ВОТ ТУТ ВОЗВРАЩАЕТСЯ null
if (canvas == null) {
Log.e("Recognized", "Cannot draw onto the canvas as it's null");
} else {
OcrResult.getWords();
OcrResult.getFoundedWordsArray("your"); // input a word to find
Log.e("Recognized", "else of drawFounded starting");
if(OcrResult.getFoundedWordNum().size()>0){
// Draw bounding boxes around each word
for (int i = 0; i < OcrResult.getFoundedWordNum().size(); i++) {
paint.setAlpha(0xFF);
paint.setColor(0xFF00CCFF);
paint.setStyle(Style.STROKE);
paint.setStrokeWidth(2);
Rect r = OcrResult.getWordBoundingBoxes().get(OcrResult.getFoundedWordNum().get(i));
canvas.drawRect(r, paint);
Toast.makeText(this, "founded", Toast.LENGTH_SHORT).show();
Log.e("Recognized", "trying to draw");
}
holderFD.unlockCanvasAndPost(canvas);
Log.e("Recognized", "unlock canvas");
//sv.setZOrderOnTop(true);
//svfd.setZOrderOnTop(false); // try another combination
}
}
}
}
Заранее спасибо вам за помощь.