Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Java Basics
Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old February 24th, 2006, 04:46 AM
Authorized User
Join Date: Dec 2003
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default problem in capturing webcam image

To capture image directly, I'm using the following code:

import java.io.*;
import java.awt.*;
import java.util.Enumeration;
import java.util.Properties;
import java.util.Vector;
import javax.media.*;
import javax.media.control.*;
import javax.media.protocol.*;
import javax.media.util.*;
import javax.media.format.RGBFormat;
import javax.media.format.VideoFormat;

import javax.media.*;
import javax.media.control.*;
import javax.media.util.*;
import java.awt.image.*;
import java.awt.event.*;

import javax.swing.*;
import javax.imageio.*;
import javax.swing.*;
import javax.swing.border.*;
import java.io.*;
import javax.media.*;
import javax.media.datasink.*;
import javax.media.format.*;
import javax.media.protocol.*;
import javax.media.util.*;
import javax.media.control.*;
import java.util.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import com.sun.image.codec.jpeg.*;
import java.io.IOException;
import java.util.Locale;
import javax.imageio.ImageReader;
import javax.imageio.spi.ImageReaderSpi;
import javax.imageio.stream.ImageInputStream;
import com.sun.media.protocol.vfw.VFWCapture; // JMF 2.1.1e version

// set up player
JPanel videoPanel = new JPanel();
// note I just set the media locator directly
MediaLocator ml = new MediaLocator("vfw://0");
try {
  Manager.setHint(Manager.LIGHTWEIGHT_RENDERER, new Boolean(true));
  player = Manager.createRealizedPlayer(ml);
  Component comp;
  if ((comp = player.getVisualComponent()) != null) {
    videoPanel.add(comp, BorderLayout.CENTER);
    videoPanel.setSize(new Dimension(320, 240));
    videoPanel.setMinimumSize(new Dimension(320, 240));
    videoPanel.setMaximumSize(new Dimension(320, 240));
catch (Exception e) {
  // process error

// action code on capture button
public void actionPerformed(ActionEvent e) {
  JComponent c = (JComponent) e.getSource();
  if (c == capture) {
    // Grab the frame
    FrameGrabbingControl fgc = (FrameGrabbingControl) player.getControl("javax.media.control.FrameGrabbi ngControl");
    Buffer buf = fgc.grabFrame();
    // Convert to image
    BufferToImage btoi = new BufferToImage((VideoFormat)buf.getFormat());
    Image img = btoi.createImage(buf);
    // now go and display the captured image

But it gives the error package javax.media does not exist. I'm using jdk 1.4. Classpath is set becoz it doesn't give error for javax.swing, which I'm using in my code. What could be the problem?

Old January 5th, 2018, 05:47 AM
Registered User
Join Date: Jan 2018
Posts: 1
Thanks: 1
Thanked 0 Times in 0 Posts
Default capturing images by webcam

I also have problems capturing images through my webcam. I want to develop an application to broadcast with live webcams porno site but I have problems when it comes to programming. I would like to know if there are any programmers in this forum who know how to develop this type of projects.

Similar Threads
Thread Thread Starter Forum Replies Last Post
Loop problem in capturing image using webcam labby BOOK: Professional Web Parts and Custom Controls ASP.NET ISBN: 0-7645-7860-X 0 January 5th, 2007 09:13 PM
Loop capturing image and generic error occured in labby C# 2005 0 December 22nd, 2006 02:55 AM
Capturing web camera image directly harini19 Java Basics 0 February 23rd, 2006 08:01 AM
use webcam with php webphp Pro PHP 0 August 29th, 2005 04:38 AM
saving image from webcam kvanchi General .NET 0 April 8th, 2005 01:49 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.