Answer the question
In order to leave comments, you need to log in
Doesn't draw on SurfaceView, android?
Hello, I need your help.
To solve my problem, I need 2 SurfaceViews: 1 to take and process frames from the camera, the second to draw the received data. So, when a Canvas is requested, the lockCanvas function returns 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
}
}
}
}
Answer the question
In order to leave comments, you need to log in
Yes, everything is there. I solved the problem by replacing the SurfaceView with my custom View. Thanks
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question