java JMF的使用(三)

2014-11-24 09:09:54 · 作者: · 浏览: 5
e.TYPE_INT_ARGB;
}
bimage = new BufferedImage(image.getWidth(null), image
.getHeight(null), type);
}
// Copy image to buffered image
Graphics g = bimage.createGraphics();
// Paint the image onto the buffered image
g.drawImage(image, 0, 0, null);
g.dispose();
return bimage;
}
private MediaLocator autoDetect() {// 自动识别功能函数
MediaLocator ml = null; // 视频采集设备对应的MediaLocator
VideoFormat currentFormat = null;// 用户定制获得视频采集设备支持的格式
Format setFormat = null;// 用户定制视频采集设备输出的格式
Format[] videoFormats = null;// 视频采集设备支持的所有格式
System.out.println(" AutoDetect for VFW");// VFW:微软的 Video for Windows
// 获得当前所有设备列表
Vector deviceList = CaptureDeviceManager.getDeviceList(null);
CaptureDeviceInfo device = CaptureDeviceManager.getDevice(url);
if (deviceList != null) {
// 根据设备列表,找出可用设备名称
for (int i = 0; i < deviceList.size(); i++) {
try {
CaptureDeviceInfo di = (CaptureDeviceInfo) deviceList
.elementAt(i);
// 如果设备名称以vfw开头
if (di.getName().startsWith("vfw:")) {
// 获得所有支持RGB格式
videoFormats = di.getFormats();
for (int j = 0; j < videoFormats.length; j++) {
// 我们只需要第一种RGB格式
if (videoFormats[j] instanceof RGBFormat) {
currentFormat = (RGBFormat) videoFormats[i];
break;
}
}
if (currentFormat == null) {
System.err.println("Search For RGBFormat Failed");
System.exit(-1);
}
// 通过设备,获得MediaLocator,这个很重要
ml = di.getLocator();
}
} catch (Exception npe) {
System.err.println("Unable to get Processor for device");
System.exit(-1);
}
}
} else {
System.err.println("No Capture Device OK");
System.exit(-1);
}
mediaLocator = ml;
return ml;// 返回可用的设备medialocator
}
public static void main(String[] args) throws NoPlayerException,
IOException {
JMFDemo demo = new JMFDemo();
demo.setSize(100, 100);
demo.autoDetect();
demo.init();
demo.play();
demo.setVisible(true);
}
}