最近用swing做了一个仿QQ的聊天程序,想加入一个视频功能,对相关的javaapi不是很熟悉,哪位有源码么?关键是获取本地图像后使用那些类来使用io操作输出等
有源码是最佳了,相关视频,书籍也可以推荐。有劳大家~~

解决方案 »

  1.   

    不太明白你什么意思!
    http://java2000.net/f36
    http://java2000.net/p13458
    图像处理
      

  2.   

    JMF应该能实现,不过没做过。
      

  3.   

    JMF,有现成的例子和源码,不过时间比较长了,好像是02年的。
      

  4.   

    我写了个自动截图的程序//主界面
    import java.awt.Button;
    import java.awt.FileDialog;
    import java.awt.FlowLayout;
    import java.awt.Frame;
    import java.awt.GridLayout;
    import java.awt.Label;
    import java.awt.Panel;
    import java.awt.TextField;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;public class UI extends Frame {
    MyBean bean = new MyBean();
    private Label pathLabel = new Label("保存路径");
    private Label timeLabel = new Label("时间间隔(/毫秒)");
    private TextField pathArea = new TextField();
    private TextField textArea = new TextField();
    private Button button = new Button("浏览");
    private Button button1 = new Button("开始");
    private Button button2 = new Button("停止"); public UI() {
    super("Auto curt!");
    pathArea.setColumns(10);
    textArea.setColumns(5);
    ButtonMonitor monitor = new ButtonMonitor(this);
    Panel panel1 = new Panel();
    Panel panel2 = new Panel();
    Panel panel3 = new Panel();
    button.addActionListener(monitor);
    button1.addActionListener(monitor);
    button2.addActionListener(monitor);
    this.setLayout(new GridLayout(3, 1));
    panel1.setLayout(new FlowLayout());
    panel2.setLayout(new FlowLayout());
    panel3.setLayout(new FlowLayout());
    panel1.add(pathLabel);
    panel1.add(pathArea);
    // panel1.add(button);
    panel2.add(timeLabel);
    panel2.add(textArea);
    panel3.add(button1);
    panel3.add(button2);
    this.add(panel1);
    this.add(panel2);
    this.add(panel3);
    this.setBounds(300, 300, 300, 300);
    this.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent we) {
    System.exit(0);
    }
    });
    this.setVisible(true); } public static void main(String[] args) {
    new UI();
    } private class ButtonMonitor implements ActionListener {
    UI ui = null; public ButtonMonitor(UI ui) {
    this.ui = ui;
    } public void actionPerformed(ActionEvent e) {
    String command = e.getActionCommand();
    if (command.equals("浏览")) {
    FileDialog dialog = new FileDialog(ui, "打开", FileDialog.LOAD);
    dialog.show();
    } else if (command.equals("开始")) {
    String imagePath = ui.pathArea.getText();
    String timeSpace = ui.textArea.getText();
    ui.bean.setImagePath(imagePath);
    ui.bean.setTimeSpace(timeSpace);
    ui.bean.check();
    ui.bean.begin();
    } else if (command.equals("停止")) {
    // System.exit(0);
    ui.bean.stop();
    }
    } }}
      

  5.   


    import java.io.File;
    import java.util.Date;
    import java.util.Timer;public class MyBean {
    Timer timer = null;
    private String imagePath;
    private String timeSpace; public String getImagePath() {
    return imagePath;
    } public void setImagePath(String imagePath) {
    this.imagePath = imagePath;
    } public String getTimeSpace() {
    return timeSpace;
    } public void setTimeSpace(String timeSpace) {
    this.timeSpace = timeSpace;
    } public void check() {// 检验文件夹是否存在,不存在的话创建一个文件夹
    File file = new File(imagePath);
    if (file.exists() == false) {
    file.mkdir();
    }
    Date date = new Date(System.currentTimeMillis());
    String newPath = date.toLocaleString().split("\\s+")[0];
    System.out.println(newPath);
    file = new File(imagePath, newPath);
    if (file.exists() == false) {
    file.mkdir();
    }
    } public void begin() {
    MyTask task = new MyTask(imagePath);
    timer = new Timer();
    timer.schedule(task, new Date(System.currentTimeMillis()), Long
    .valueOf(timeSpace).longValue());
    } public void stop() {
    timer.cancel();
    } public static void main(String[] args) {
    MyBean bean = new MyBean();
    bean.check();
    }}
      

  6.   

    截图实现类
    主要是用Robot类的createScreenCapture方法
    3个源文件你编译一下就可以运行import java.awt.AWTException;
    import java.awt.Dimension;
    import java.awt.Rectangle;
    import java.awt.Robot;
    import java.awt.Toolkit;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    import java.util.Date;
    import java.util.TimerTask;import javax.imageio.ImageIO;public class MyTask extends TimerTask {
    String parentPath = null;
    Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();//获得屏幕大小
    Rectangle rectangle = new Rectangle(dimension);//构造矩形
    Robot robot = null;
    BufferedImage image = null;
    String fileName = null; public MyTask(String parentString) {
    this.parentPath = parentString;
    } public void run() {
    try {
    robot = new Robot();
    image = robot.createScreenCapture(rectangle);//截图
    Date date = new Date(System.currentTimeMillis());
    String dateString = date.toLocaleString();
    fileName = dateString.split("\\s+")[0] + "\\"
    + dateString.split("\\s+")[1];
    fileName = fileName.replaceAll("\\:", "_");
    System.out.println(fileName);
    fileName = parentPath + "\\" + fileName + ".png";
    System.out.println(fileName);
    File imageFile = new File(fileName);
    ImageIO.write(image, "PNG", imageFile); } catch (AWTException e) { } catch (IOException e) { e.printStackTrace();
    }
    }}
      

  7.   

    谢谢ls的源码,非常感谢~~.ps:一碗豆浆,jmf的源码还在么,如果在的话不妨发给我吧,我想看看实现的逻辑。谢谢[email protected]
      

  8.   

    JMF可以实现,不过应该没有相关的中文书籍,英文的都很少,以前好像看到过一个例子,上网搜搜吧,可以实现的,截取到摄像头这个设备,就可以了。jmf做起来很麻烦,套了很多层的类,唉,java的设计很麻烦。