Coder Social home page Coder Social logo

java_swing_webcam's Introduction

Java Swing Webcam Capture and Save

Create Java Swing Project to Capture and Save Webcam Image

Getting Started

Download and open in Netbean 8.xx IDE

Prerequisites

  1. bridj-0.7.0.jar
  2. slf4j-api-1.7.2.jar
  3. webcam-capture-0.3.13-20180202.082008-3.jar

//////////SWING COMPONENT////////////
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel panelCam;

//////////  IMPORT /////////////////////

import com.github.sarxos.webcam.Webcam;
import com.github.sarxos.webcam.WebcamPanel;
import com.github.sarxos.webcam.WebcamResolution;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.HeadlessException;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JOptionPane;

/////////// IN MAIN CLASS/////////

public class NewJFrame extends javax.swing.JFrame {
    private final Dimension ds=new Dimension(450,360);
    private final Dimension cs= WebcamResolution.VGA.getSize();
    private final Webcam wCam=Webcam.getDefault();
    private final  WebcamPanel wCamPanel=new WebcamPanel(wCam,ds,false);  
    
////// AFTER INIT COMPONENT ////////////

    public NewJFrame() {
        initComponents();
        wCam.setViewSize(cs);
        wCamPanel.setFillArea(true);
        panelCam.setLayout(new FlowLayout());
        panelCam.add(wCamPanel);      
 }
 
 //////////////// AT CAPTURING EVENT ///////////////// 
 
        Thread t = new Thread(){
        @Override        
        public void run(){
        wCamPanel.start();
    }
    };
    t.setDaemon(true);
    t.start();
    
 /////////////////// SAVING EVENT ///////////
 
  try{
          File file= new File(String.format("capture-%d.jpg",System.currentTimeMillis())) ;
        ImageIO.write(wCam.getImage(), "JPG", file);
        JOptionPane.showMessageDialog(this, "image saved on :\n" + file.getAbsolutePath(),"CamCap",1);
        }
        catch(HeadlessException | IOException e){
            JOptionPane.showMessageDialog(this,"Image Not Saved :/n"+e.getMessage(),"Cam",0);
            
        }
 

Installing

Clone git and open dist folder and run JavaApplication2.jar in windows environment

Built With

Contributing & Issue

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Authors

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments

  • Bartosz Firyn

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.