bjfhs Active Member Licensed User Feb 12, 2019 #1 When I use java inline(javacv) to open camera,I can't get any thing.Can you give me any advice ? B4X: NativeMe.RunMethod("showVideo",Null) B4X: public static void showVideo() { OpenCVFrameGrabber grabber = new OpenCVFrameGrabber(0); try{ grabber.start(); CanvasFrame canvas = new CanvasFrame("camera"); canvas.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); canvas.setAlwaysOnTop(true); while(true) { if(!canvas.isDisplayable()) { grabber.stop(); System.exit(2); } canvas.showImage(grabber.grab()); Thread.sleep(500); } } catch (Exception e) { } }
When I use java inline(javacv) to open camera,I can't get any thing.Can you give me any advice ? B4X: NativeMe.RunMethod("showVideo",Null) B4X: public static void showVideo() { OpenCVFrameGrabber grabber = new OpenCVFrameGrabber(0); try{ grabber.start(); CanvasFrame canvas = new CanvasFrame("camera"); canvas.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); canvas.setAlwaysOnTop(true); while(true) { if(!canvas.isDisplayable()) { grabber.stop(); System.exit(2); } canvas.showImage(grabber.grab()); Thread.sleep(500); } } catch (Exception e) { } }
bjfhs Active Member Licensed User Feb 14, 2019 #2 The code is ok,my camera is bad. But I find a new question,when the video is show,the main window can't do any thing,why? Upvote 0
The code is ok,my camera is bad. But I find a new question,when the video is show,the main window can't do any thing,why?
Daestrum Expert Licensed User Longtime User Feb 14, 2019 #3 It sounds like it is running on the main thread and not allowing the ui to update. You probably need to run the routine on either a, a different thread to the main program b, Use Application.RunLater to run it. Upvote 0
It sounds like it is running on the main thread and not allowing the ui to update. You probably need to run the routine on either a, a different thread to the main program b, Use Application.RunLater to run it.
bjfhs Active Member Licensed User Feb 14, 2019 #4 Daestrum said: It sounds like it is running on the main thread and not allowing the ui to update. You probably need to run the routine on either a, a different thread to the main program b, Use Application.RunLater to run it. Click to expand... You are right.but I don't know how to start a new thread in B4J(or java inline) and how to use Application.RunLater to run it. Can you help me? All the code in the attached file. Attachments test.zip 420.7 KB · Views: 189 Upvote 0
Daestrum said: It sounds like it is running on the main thread and not allowing the ui to update. You probably need to run the routine on either a, a different thread to the main program b, Use Application.RunLater to run it. Click to expand... You are right.but I don't know how to start a new thread in B4J(or java inline) and how to use Application.RunLater to run it. Can you help me? All the code in the attached file.
bjfhs Active Member Licensed User Feb 18, 2019 #5 I can do it know,use new thread in java inline. Upvote 0