Results 1 to 1 of 1
- 04-16-2011, 09:46 PM #1Member
- Join Date
- Apr 2011
- Rep Power
Hi all, I have a problem with JFM.
i am trying to capture an image from my web cam.
i can show the image through my JMF Studio but when i try to use a code it looks like it doesnt know that the device even exists.
here is the code:
public static void main(String args) throws Exception
// Create capture device
CaptureDeviceInfo deviceInfo = CaptureDeviceManager.getDevice("vfw:Microsoft WDM Image Capture (Win32):0");
Player player = Manager.createRealizedPlayer(deviceInfo.getLocator ());
// Wait a few seconds for camera to initialise (otherwise img==null)
// // Grab a frame from the capture device
FrameGrabbingControl frameGrabber = (FrameGrabbingControl)player.getControl("javax.med ia.control.FrameGrabbingControl");
Buffer buf = frameGrabber.grabFrame();
// Convert frame to an buffered image so it can be processed and saved
Image img = (new BufferToImage((VideoFormat)buf.getFormat()).create Image(buf));
BufferedImage buffImg = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_RGB);
Graphics2D g = buffImg.createGraphics();
g.drawImage(img, null, null);
// Overlay curent time on image
g.setFont(new Font("Verdana", Font.BOLD, 16));
g.drawString((new Date()).toString(), 10, 25);
// Save image to disk as PNG
ImageIO.write(buffImg, "png", new File("c:\\webcam.png"));
// Stop usin webcam
CaptureDeviceInfo device = CaptureDeviceManager.getDevice("vfw:Microsoft WDM Image Capture (Win32):0");
when i am trying it it says "Exception in thread "main" java.lang.NullPointerException
its like it doesnt know the device exists even though i can use it through the JMF studio.
and if i am trying to rum just from the variable "device" to the end(and putting all the rest in "//" it says "no device".
what should i do.
I even tried to reinstall it in another directory and run as admin but it did not work.