javaCV在rcp中拍照

1、由于jms很久没有更新,不支持系统64,故选用javaCV进行拍照

2、源码

final OpenCVFrameGrabber grabber = new OpenCVFrameGrabber(0);
        
        
        camBtn.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                
                canvas.getDisplay().syncExec(new Runnable() {
                    @Override
                    public void run() {
                        IplImage images = null;
                        try {
                            grabber.setImageHeight(240);
                            grabber.setImageWidth(320);
                            grabber.start();
                            images = grabber.grab();
                            int width = images.width();  
                            int height = images.height();  
                            canvas.setWidth(width);
                            canvas.setHeiht(height);
                            
                            //onscreen buffer for image capture  
                            final BufferedImage bImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);  
                            
                            TimerAction timerAction = new TimerAction(canvas);  
                            final Timer timer=new Timer(10, timerAction);  
                            timerAction.setTimer(timer);  
                            
                            while (canvas.isVisible() && (images = grabber.grab()) != null) {
                                if(!timer.isRunning()) { //when animation is on, pause real-time display 
                                    final BufferedImage bufferedImage = images.getBufferedImage(images.getBufferedImageType() == 0 ? 1.0D : 1.0D, false);
                                    final ImageData data = CamIamgeUtil.convertToImageData(bufferedImage);
                                    //canvas.setImage(data);
                                    final Image img = new Image(canvas.getDisplay(), data);
                                    final Display display=canvas.getDisplay();
                                    // Draw the new data onto the image
                                    Image frameImage = new Image(display,data);
                                    
                                    GC gc=new GC(canvas);
                                    
                                    gc.drawImage(frameImage,data.x,data.y);
                                    frameImage.dispose();
                                    canvas.redraw();
                                }  
                            }
                        }catch(java.lang.Exception ex){
                            ex.printStackTrace();
                        }
                    }

                });


你可能感兴趣的:(RCP,javacv,rcp)