{"action":"created","issue":{"url":"https://api.github.com/repos/bytedeco/javacv/issues/301","labels_url":"https://api.github.com/repos/bytedeco/javacv/issues/301/labels{/name}","comments_url":"https://api.github.com/repos/bytedeco/javacv/issues/301/comments","events_url":"https://api.github.com/repos/bytedeco/javacv/issues/301/events","html_url":"https://github.com/bytedeco/javacv/issues/301","id":125347256,"number":301,"title":"newer to the javacv","user":{"login":"Sligths","id":16460516,"avatar_url":"https://avatars.githubusercontent.com/u/16460516?v=3","gravatar_id":"","url":"https://api.github.com/users/Sligths","html_url":"https://github.com/Sligths","followers_url":"https://api.github.com/users/Sligths/followers","following_url":"https://api.github.com/users/Sligths/following{/other_user}","gists_url":"https://api.github.com/users/Sligths/gists{/gist_id}","starred_url":"https://api.github.com/users/Sligths/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Sligths/subscriptions","organizations_url":"https://api.github.com/users/Sligths/orgs","repos_url":"https://api.github.com/users/Sligths/repos","events_url":"https://api.github.com/users/Sligths/events{/privacy}","received_events_url":"https://api.github.com/users/Sligths/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-01-07T08:23:19Z","updated_at":"2016-01-07T14:20:17Z","closed_at":null,"body":"```java\r\npackage org.bytedeco.javacv;\r\n\r\nimport java.awt.Graphics2D;\r\nimport java.awt.Paint;\r\nimport java.awt.event.ActionEvent;\r\nimport java.awt.event.ActionListener;\r\nimport java.awt.event.MouseAdapter;\r\nimport java.awt.event.MouseEvent;\r\nimport java.awt.image.BufferedImage;\r\nimport java.io.File;\r\nimport java.io.IOException;\r\nimport javax.imageio.ImageIO;\r\nimport javax.swing.Timer;\r\n\r\nimport org.bytedeco.javacpp.opencv_core.IplImage;\r\nimport org.bytedeco.javacv.FrameGrabber.Exception;\r\n\r\n\r\npublic class Demo {  \r\n  public static String savedImageFile = \"D:/Eclipse/test1.png\";  \r\n    \r\n  //timer for image capture animation  \r\n  static class TimerAction implements ActionListener {  \r\n      private Graphics2D g;  \r\n      private CanvasFrame canvasFrame;  \r\n      private int width,height;         \r\n      private int delta=10;  \r\n      private int count = 0;  \r\n        \r\n      private Timer timer;  \r\n      public void setTimer(Timer timer){  \r\n          this.timer = timer;  \r\n      }  \r\n         \r\n      public TimerAction(CanvasFrame canvasFrame){  \r\n          this.g = (Graphics2D)canvasFrame.getCanvas().getGraphics();   \r\n          this.canvasFrame = canvasFrame;  \r\n          this.width = canvasFrame.getCanvas().getWidth();             \r\n      }\r\n\r\n\t@Override\r\n\tpublic void actionPerformed(ActionEvent arg0) {\r\n\t\t// TODO Auto-generated method stub\r\n        int offset = delta*count;  \r\n        if(width-offset>=offset && height-offset >= offset) {          \r\n            g.drawRect(offset, offset, width-2*offset, height-2*offset);  \r\n            canvasFrame.repaint();  \r\n            count++;  \r\n        }else{  \r\n            //when animation is done, reset count and stop timer.  \r\n            timer.stop();  \r\n            System.out.println(\" this is actionPerformd\");\r\n            count = 0; \r\n\t}  \r\n        canvasFrame.dispose();\r\n  }  \r\n }\r\n\tpublic static void main(String[] args) throws\r\n  \t\t\t\t\tException, java.lang.Exception {  \r\n      //open camera source \r\n      OpenCVFrameGrabber grabber = new OpenCVFrameGrabber(0);  \r\n      \tgrabber.start();      \r\n      OpenCVFrameConverter.ToIplImage converter=new OpenCVFrameConverter.ToIplImage();\r\n      \r\n      //create a frame for real-time image display  \r\n      CanvasFrame canvasFrame = new CanvasFrame(\"Camera\"); \r\n//      IplImage image=grabber.getGamma();\r\n      IplImage image = converter.convert(grabber.grab());  \r\n      \r\n      int width = image.width();  \r\n      int height = image.height();  \r\n      canvasFrame.setCanvasSize(width, height); \r\n      \r\n      System.out.println(\"001\");\r\n      //onscreen buffer for image capture  \r\n      final BufferedImage bImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);  \r\n      Graphics2D bGraphics = bImage.createGraphics();       \r\n      //animation timer  \r\n      TimerAction timerAction = new TimerAction(canvasFrame);      \r\n      final Timer timer=new Timer(10,timerAction) ;\r\n      timerAction.setTimer(timer); \r\n//      final Timer timer=new Timer(10,timerAction);  \r\n       \r\n         \r\n      //click the frame to capture an image             \r\n      canvasFrame.getCanvas().addMouseListener(new MouseAdapter(){\r\n          public void mouseClicked(MouseEvent e){       \r\n              timer.start(); //start animation  \r\n              try {  \r\n                  ImageIO.write(bImage, \"jpg\", new File(savedImageFile));  \r\n              } catch (IOException e1) {  \r\n                  e1.printStackTrace();  \r\n              }                     \r\n          }                  \r\n      });                   \r\n      //real-time image display  \r\n      while(canvasFrame.isVisible() && (converter.convert(grabber.grab())) != null){  \r\n          if(!timer.isRunning()) { //when animation is on, pause real-time display  \r\n              converter.convert(image); \r\n              CanvasFrame.getDefaultGamma();\r\n              //draw the onscreen image simutaneously \r\n              bGraphics.drawImage(bImage,null,0,0);\r\n//              bGraphics.setPaint((Paint) image); \r\n          }  \r\n      }  \r\n        \r\n      //release resources  \r\n      image.release();  \r\n      grabber.stop();  \r\n      canvasFrame.dispose();  \r\n\t}  \r\n  }\r\n```\r\nI can't get the result as it should be ,and how can i slove it  to open the videocapture and draw a picture as i want."},"comment":{"url":"https://api.github.com/repos/bytedeco/javacv/issues/comments/169677271","html_url":"https://github.com/bytedeco/javacv/issues/301#issuecomment-169677271","issue_url":"https://api.github.com/repos/bytedeco/javacv/issues/301","id":169677271,"user":{"login":"saudet","id":3328023,"avatar_url":"https://avatars.githubusercontent.com/u/3328023?v=3","gravatar_id":"","url":"https://api.github.com/users/saudet","html_url":"https://github.com/saudet","followers_url":"https://api.github.com/users/saudet/followers","following_url":"https://api.github.com/users/saudet/following{/other_user}","gists_url":"https://api.github.com/users/saudet/gists{/gist_id}","starred_url":"https://api.github.com/users/saudet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/saudet/subscriptions","organizations_url":"https://api.github.com/users/saudet/orgs","repos_url":"https://api.github.com/users/saudet/repos","events_url":"https://api.github.com/users/saudet/events{/privacy}","received_events_url":"https://api.github.com/users/saudet/received_events","type":"User","site_admin":false},"created_at":"2016-01-07T14:20:17Z","updated_at":"2016-01-07T14:20:17Z","body":"What is the result you are expecting?"}}