📄 程序说明.txt
字号:
1.安装 JMF2.1windows 板,在classpath中包含:jmf.jar和sound.jar;在path中需要包含jmf
动态库的路径。
2.在调式jmf程序时遇到的问题:EXception in thread "VFM Request Thread" no jmvfw in
java library path; 解决方法:复制jmvfw.dll和jmvcm.dll从windows/system32到jre的bin目录;
3.装上摄像头后别忘了注册;jmfregistry.exe /capture Devices /detect capture devices
4.实时采集数据并显示:
1).多媒体数据。核心代码:Player player=null;
Component vc=null;
Component cc=null;
URL theURL;
theURL=new URL(getClass().getResource("."),mediaAddress);
mediaAddress=file:///d:/sport.mov;
player=Manager.createPlayer(theURL);
实现:ControllerListener接口:vc=player.getVisualComponent();
cc=player.getControlComponent();
add(BorderLayout.CENTER,vc);
add(BorderLayout.SOUTH,cc);
2).从摄像头实时采集数据并显示。核心代码:主要是MediaLocator 对象变了;
变成摄像头的驱动;
CaptureDeviceInfo di=CaptureDeviceManger.getDevice("vfw:Microsoft WDM Image
Capture (Win32):0");
MediaLocator ml=di.getLocator();
Player thePlayer=Manager.createPlayer(ml);
5.拍照程序代码;
FrameGrabbingControl fgc =(FrameGrabbingControl)thePlayer.getControl("
javax.media.control.FrameGrabbingControl");
Buffer buf = fgc.grabFrame(); // 获取当前祯并存入Buffer类
BufferToImage btoi = new BufferToImage((VideoFormat) buf.getFormat());
Image img = btoi.createImage(buf); // 得到了图像;
6.绘图程序框架:
public class ImageCapture extends JFrame {
int xpoint = 40, ypoint = 40;
private Image image;
public ImageCapture(Image img) {
super("ImageCapture");
this.image=img;
setSize(400, 400);
setVisible(true);
}
public void paint(Graphics g) {
System.out.println(g);
g.drawImage(image,xpoint,ypoint,this);
}
}
7.保存图片的代码:
String fileAddr="d://image.jpg";
BufferedImage bi = (BufferedImage) createImage(width,hight);
Graphics2D g2 = bi.createGraphics();
g2.drawImage(image, null, null);
FileOutputStream out = null;
try
{
File f = new File(fileAddr);
out = new FileOutputStream(f);
}
catch (java.io.FileNotFoundException io)
{
System.out.println("File Not Found");
}
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");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -