Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2005

Tip: Looking for answers? Try searching our database.

Question regardig JMF

Thread view: 
René Beltman - 23 Dec 2005 18:56 GMT
Hello everyone,

With the JMF I am trying to locally save an image provided by a webcam.

For this I need the BufferToImage class. This class requires a Buffer
object, but how do I configure this buffer object or how can I get an
already configured buffer?

The following code is not creating an image:
import javax.media.*;
import javax.media.format.*;
import javax.media.protocol.*;
import javax.media.util.BufferToImage;

public class Webcam {
public static void main(String [] args) throws Throwable {

 // get the webcam
 CaptureDeviceInfo info = CaptureDeviceManager.getDevice("vfw:Microsoft WDM
Image Capture (Win32):0");

 DataSource src = Manager.createDataSource(info.getLocator());

 src.connect();
 src.start();

 if (src instanceof PullBufferDataSource) {

  PullBufferDataSource dataSource = (PullBufferDataSource) src;

  PullBufferStream [] dataStreams = dataSource.getStreams();

  System.out.println("PullBufferStream:");
  for (int i = 0; i < dataStreams.length; i++) {
   System.out.println(i + ": " + dataStreams[i]);
  }

 } else if (src instanceof PullDataSource) {

  PullDataSource dataSource = (PullDataSource) src;

  PullSourceStream [] dataStreams = dataSource.getStreams();

  System.out.println("PullDataSource:");
  for (int i = 0; i < dataStreams.length; i++) {
   System.out.println(i + ": " + dataStreams[i]);
  }

 } else if (src instanceof PushBufferDataSource) {

  PushBufferDataSource dataSource = (PushBufferDataSource) src;

  PushBufferStream [] dataStreams = dataSource.getStreams();

  System.out.println("PushBufferDataSource:");
  for (int i = 0; i < dataStreams.length; i++) {
   System.out.println(i + ": " + dataStreams[i]);
  }

  System.out.println("preparing a capture...");

  PushBufferStream dataStream = dataStreams[0];

  System.out.println("created a dataStream, now creating a buffer...");

  Buffer buffer = new Buffer();

  System.out.println("created a buffer, now configuring...");

  buffer.setDuration(1000000);

  System.out.println("buffer configured. Now starting to read...");

  dataStream.read(buffer);

  System.out.println("reading finished, now detecting a format...");

  Format [] formats = info.getFormats();

  VideoFormat format = null;
  for (int i = 0; i < formats.length && format == null; i++) {
   format = formats[i] instanceof VideoFormat ? (VideoFormat) formats[i] :
null;
  }

  System.out.println("format " + format + " detected, now starting to
create an BufferToImage instance");

  BufferToImage bti = new BufferToImage(format);

  System.out.println("Instance ready, now creating an image");

  java.awt.Image image = bti.createImage(buffer);

  if (image != null) {
   System.out.println("Image created");
  } else {
   System.out.println("The image could not been created");
  }

 } else if (src instanceof PushDataSource) {

  PushDataSource dataSource = (PushDataSource) src;

  PushSourceStream [] dataStreams = dataSource.getStreams();

  System.out.println("PushDataSource:");
  for (int i = 0; i < dataStreams.length; i++) {
   System.out.println(i + ": " + dataStreams[i]);
  }

 } else {
  System.out.println(src.getClass().getName());
 }
}
}

Does someone know wat I am doing wrong and how can I correct it? Thanks in
advantage.

Greetings,

René Beltman.
JScoobyCed - 24 Dec 2005 02:01 GMT
> Hello everyone,
>
[quoted text clipped - 3 lines]
> object, but how do I configure this buffer object or how can I get an
> already configured buffer?

[...]
>    Buffer buffer = new Buffer();
>
[quoted text clipped - 20 lines]
>
>    BufferToImage bti = new BufferToImage(format);

Why are you trying to create a format out of the box. The Buffer object
can give it to you. I am not sure it will solve your issue, but I think
it worths trying:

<code>
VideoFormat format = (VideoFormat) buffer.getFormat();
BufferToImage bti = new BufferToImage(format);
Image image = bti.createImage(buffer);
</code>

Signature

JSC



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.