主题:[讨论]eclipse中能运行这个程序,export后的就运行不了
eclipse版本:SDK3.4.2
安装的包:jmf-2.1.1e
系统环境:Windows xp
我写了一个摄像头捕获的程序,在eclipse中能够运行,但是将之导出就不能启动,输出“没有找到视频捕捉设备!”
我的导出直接用的是:右键——>导出——>Ruunable JAR file。
要运行程序需要提前安装jmf。我安装的版本是2.1.1e
我想问这么导出不行么?请大家帮我解决一下,搜了好多都没有找到解决的办法。
代码如下:
import java.io.*;
import javax.media.*;
import javax.media.util.BufferToImage;
import javax.media.control.*;
import javax.media.format.*;
import java.awt.image.*;
import java.awt.*;
import java.awt.Component;
import com.sun.image.codec.jpeg.*;
import javax.swing.*;
public class Capture2 extends JFrame
{
/**
*
*/
private static final long serialVersionUID = 1L;
CaptureDeviceInfo di=null;
Player player=null;
MediaLocator ml=null;
private Component comp=null;
String str1 = "vfw:Logitech USB Video Camera:0";
String string1="vfw:Microsoft WDM Image Capture (Win32):0"; //考虑设备是不是有多种
public Capture2()
{
di=CaptureDeviceManager.getDevice(string1); //获得捕捉设备
if(di==null)
{
System.out.println(" ");
System.exit(-1); //设备出错,返回-1
}
ml=di.getLocator(); //找到捕捉设备的地址
try
{
player=Manager.createRealizedPlayer(ml); //建立一个player
player.start();
comp=player.getVisualComponent(); //该语句是干嘛的?
if(comp!=null)
{
getContentPane().setLayout(new BorderLayout());
JPanel p=new JPanel();
p.setLayout(new BorderLayout());
p.add(comp, BorderLayout.CENTER);
getContentPane().add(p, BorderLayout.CENTER);
/* FrameGrabbingControl fgc =(FrameGrabbingControl)player.getControl("javax.media.control.FrameGrabbingControl");
buf=fgc.grabFrame();
btoi = new BufferToImage((VideoFormat)buf.getFormat());//??查询功能:把视频流换成图像?
img = btoi.createImage(buf);*/
}
}
catch (Exception e)
{
player.close();
e.printStackTrace();
System.exit(-1);
}
/*
//保存图片
BufferedImage bi = new BufferedImage(640, 480, BufferedImage.TYPE_INT_RGB);//(BufferedImage)createImage(100, 100);
Graphics2D g2 = bi.createGraphics();
g2.drawImage(img, null, null);
FileOutputStream out = null;
try
{
out=new FileOutputStream("1.jpeg"); //没有见到输入??
}
catch (java.io.FileNotFoundException io)
{
System.out.println("File Not Found");
System.exit(-1);
}
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out); //该处有问题
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bi);
param.setQuality(1f, false); //不压缩图像
encoder.setJPEGEncodeParam(param);
try
{
encoder.encode(bi);
out.close();
}
catch (java.io.IOException io)
{
System.out.println("IOException");
System.exit(-1);
} */
//player.close();
}
public static void main(String args[]) throws Exception
{
Capture2 c = new Capture2();
c.setVisible(true);
c.setSize(200, 250);
c.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
PAI p=new PAI(c.player, 1, 3);
p.start();
System.out.println("main函数结束");
}
}
class PAI extends Thread
{
private Buffer buf = null;
private BufferToImage btoi = null;
private Image img=null;
//private Component comp=null;
private Player player;
private int t;
private int n;
public PAI(Player p, int t, int n)
{
this.player=p;
this.t=t*10000;
this.n=n;
}
public void run()
{
if(player==null)
{
System.exit(-1);
}
for(int i=0; i <n; i++)
{
try
{
Thread.sleep(t);
FrameGrabbingControl fgc =(FrameGrabbingControl)player.getControl("javax.media.control.FrameGrabbingControl");
buf=fgc.grabFrame();
btoi = new BufferToImage((VideoFormat)buf.getFormat());//??查询功能:把视频流换成图像?
img = btoi.createImage(buf);
}
catch (Exception e)
{
player.close();
e.printStackTrace();
System.exit(-1);
}
//保存图片
BufferedImage bi = new BufferedImage(640, 480, BufferedImage.TYPE_INT_RGB);//(BufferedImage)createImage(100, 100);
Graphics2D g2 = bi.createGraphics();
g2.drawImage(img, null, null);
FileOutputStream out = null;
try
{
out=new FileOutputStream((i+".jpeg")); //没有见到输入??
}
catch (java.io.FileNotFoundException io)
{
System.out.println("File Not Found");
System.exit(-1);
}
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out); //该处有问题
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bi);
param.setQuality(1f, false); //不压缩图像
encoder.setJPEGEncodeParam(param);
try
{
encoder.encode(bi);
out.close();
}
catch (java.io.IOException io)
{
System.out.println("IOException");
System.exit(-1);
}
}}
}
安装的包:jmf-2.1.1e
系统环境:Windows xp
我写了一个摄像头捕获的程序,在eclipse中能够运行,但是将之导出就不能启动,输出“没有找到视频捕捉设备!”
我的导出直接用的是:右键——>导出——>Ruunable JAR file。
要运行程序需要提前安装jmf。我安装的版本是2.1.1e
我想问这么导出不行么?请大家帮我解决一下,搜了好多都没有找到解决的办法。
代码如下:
import java.io.*;
import javax.media.*;
import javax.media.util.BufferToImage;
import javax.media.control.*;
import javax.media.format.*;
import java.awt.image.*;
import java.awt.*;
import java.awt.Component;
import com.sun.image.codec.jpeg.*;
import javax.swing.*;
public class Capture2 extends JFrame
{
/**
*
*/
private static final long serialVersionUID = 1L;
CaptureDeviceInfo di=null;
Player player=null;
MediaLocator ml=null;
private Component comp=null;
String str1 = "vfw:Logitech USB Video Camera:0";
String string1="vfw:Microsoft WDM Image Capture (Win32):0"; //考虑设备是不是有多种
public Capture2()
{
di=CaptureDeviceManager.getDevice(string1); //获得捕捉设备
if(di==null)
{
System.out.println(" ");
System.exit(-1); //设备出错,返回-1
}
ml=di.getLocator(); //找到捕捉设备的地址
try
{
player=Manager.createRealizedPlayer(ml); //建立一个player
player.start();
comp=player.getVisualComponent(); //该语句是干嘛的?
if(comp!=null)
{
getContentPane().setLayout(new BorderLayout());
JPanel p=new JPanel();
p.setLayout(new BorderLayout());
p.add(comp, BorderLayout.CENTER);
getContentPane().add(p, BorderLayout.CENTER);
/* FrameGrabbingControl fgc =(FrameGrabbingControl)player.getControl("javax.media.control.FrameGrabbingControl");
buf=fgc.grabFrame();
btoi = new BufferToImage((VideoFormat)buf.getFormat());//??查询功能:把视频流换成图像?
img = btoi.createImage(buf);*/
}
}
catch (Exception e)
{
player.close();
e.printStackTrace();
System.exit(-1);
}
/*
//保存图片
BufferedImage bi = new BufferedImage(640, 480, BufferedImage.TYPE_INT_RGB);//(BufferedImage)createImage(100, 100);
Graphics2D g2 = bi.createGraphics();
g2.drawImage(img, null, null);
FileOutputStream out = null;
try
{
out=new FileOutputStream("1.jpeg"); //没有见到输入??
}
catch (java.io.FileNotFoundException io)
{
System.out.println("File Not Found");
System.exit(-1);
}
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out); //该处有问题
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bi);
param.setQuality(1f, false); //不压缩图像
encoder.setJPEGEncodeParam(param);
try
{
encoder.encode(bi);
out.close();
}
catch (java.io.IOException io)
{
System.out.println("IOException");
System.exit(-1);
} */
//player.close();
}
public static void main(String args[]) throws Exception
{
Capture2 c = new Capture2();
c.setVisible(true);
c.setSize(200, 250);
c.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
PAI p=new PAI(c.player, 1, 3);
p.start();
System.out.println("main函数结束");
}
}
class PAI extends Thread
{
private Buffer buf = null;
private BufferToImage btoi = null;
private Image img=null;
//private Component comp=null;
private Player player;
private int t;
private int n;
public PAI(Player p, int t, int n)
{
this.player=p;
this.t=t*10000;
this.n=n;
}
public void run()
{
if(player==null)
{
System.exit(-1);
}
for(int i=0; i <n; i++)
{
try
{
Thread.sleep(t);
FrameGrabbingControl fgc =(FrameGrabbingControl)player.getControl("javax.media.control.FrameGrabbingControl");
buf=fgc.grabFrame();
btoi = new BufferToImage((VideoFormat)buf.getFormat());//??查询功能:把视频流换成图像?
img = btoi.createImage(buf);
}
catch (Exception e)
{
player.close();
e.printStackTrace();
System.exit(-1);
}
//保存图片
BufferedImage bi = new BufferedImage(640, 480, BufferedImage.TYPE_INT_RGB);//(BufferedImage)createImage(100, 100);
Graphics2D g2 = bi.createGraphics();
g2.drawImage(img, null, null);
FileOutputStream out = null;
try
{
out=new FileOutputStream((i+".jpeg")); //没有见到输入??
}
catch (java.io.FileNotFoundException io)
{
System.out.println("File Not Found");
System.exit(-1);
}
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out); //该处有问题
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bi);
param.setQuality(1f, false); //不压缩图像
encoder.setJPEGEncodeParam(param);
try
{
encoder.encode(bi);
out.close();
}
catch (java.io.IOException io)
{
System.out.println("IOException");
System.exit(-1);
}
}}
}