/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package jmftest;
import javax.swing.*;
import java.io.*;
import javax.media.*;
import javax.media.format.*;
import javax.media.util.*;
import javax.media.control.*;
import java.applet.Applet;
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import com.sun.image.codec.jpeg.*;
public class WebCamSwing extends Applet implements ActionListener {
public static Player player = null;
private CaptureDeviceInfo di = null;
private MediaLocator ml = null;
/** * 拍照按钮 */
private JButton capture = null;
/** * 保存按钮 */
private JButton save = null;
private JTextField num = null;
private Buffer buf = null;
private Image img = null;
private VideoFormat vf = null;
private BufferToImage btoi = null;
private ImagePanel imgpanel = null;
/** * 选取框的x,y,width,height参数的默认值 */
private int rectX;
private int rectY;
private int rectWidth = 300;
private int rectHeight = 200;
private int imgWidth = 320;
private int imgHeight = 240;
/** * 默认保存文件名 */
private String fname = "test";
public WebCamSwing() {
setLayout(new BorderLayout());
setSize(320, 550);
imgpanel = new ImagePanel();
imgpanel.addMouseMotionListener(imgpanel);
capture = new JButton("拍照");
capture.addActionListener(this);
save = new JButton("保存");
save.addActionListener(this);
num = new JTextField();
String str1 = "vfw:Logitech USB Video Camera:0";
String str2 = "vfw:Microsoft WDM Image Capture (Win32):0";
di = CaptureDeviceManager.getDevice(str2);
ml = di.getLocator();
try {
- 1
- 2
- 3
- 4
- 5
前往页