我把程序分為兩種
首先到SUN下載最新的JMF
然後
技術關鍵
利用JMF
//利用這三個類分別獲取攝像頭驅動
public static Player player = null;
private CaptureDeviceInfo di = null;
private MediaLocator ml = null;
//文檔中提供的驅動寫法
String str
String str
di = CaptureDeviceManager
ml = di
try
{
player = Manager
player
Component comp;
if ((comp = player
{
add(comp
}
}
catch (Exception e)
{
e
}
接下來就是點擊拍照
代碼也是很簡單
private JButton capture;
private Buffer buf = null;
private BufferToImage btoi = null;
private ImagePanel imgpanel = null;
private Image img = null;
private ImagePanel imgpanel = null;
JComponent c = (JComponent) e
if (c == capture)//如果按下的是拍照按鈕
{
FrameGrabbingControl fgc =(FrameGrabbingControl) player
buf = fgc
btoi = new BufferToImage((VideoFormat) buf
img = btoi
imgpanel
}
保存圖像的就不多說了
BufferedImage bi = (BufferedImage) createImage(imgWidth
Graphics
g
FileOutputStream out = null;
try
{
out = new FileOutputStream(s);
}
catch (java
{
System
}
JPEGImageEncoder encoder = JPEGCodec
JPEGEncodeParam param = encoder
param
encoder
try
{
encoder
out
}
catch (java
{
System
}
已經申請將JWebCam建立為一個開源項目
From:http://tw.wingwit.com/Article/program/Java/Javascript/201311/25453.html