?? 程序說明.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 + -