JPEG Grabber - bug in JMF???

Dear all.
I am trying to use a FrameGrabbingControl to grab JPEG images from a webcam.
Every so often, the BufferToImage.createImage(buf) <see below> fails, giving a null image. After it fails once, it never recovers, it will always fail - almost like the Player gets itself into an invalid state???
FrameGrabberException is an exception class I have defined. It never gets thrown!
Many thanks, I'm really stuck with this one.
Iain A. Mcleod
import javax.media.*;
import javax.media.control.*;
import javax.media.protocol.*;
import javax.media.util.*;
import javax.media.format.*;
public class FrameGrabber extends Thread {
private Player player;
public FrameGrabber(CaptureDeviceInfo cdi, Format format){
connectToPlayer(cdi,format);
start();
    private void connectToPlayer(CaptureDeviceInfo cdi, Format format) throws FrameGrabberException{
        /*  To use this device we need a MediaLocator  */
        MediaLocator loc = cdi.getLocator();
        if (loc == null) {
            throw new FrameGrabberException("Unable to get MediaLocator for video device");
        try{
            player = Manager.createRealizedPlayer(loc);
        }catch (Exception e){
            throw new FrameGrabberException("Could not get realized player for webcam: "+e.getMessage());
        player.start();
public void run(){
while(true){
                FrameGrabbingControl fgc = (FrameGrabbingControl)player.getControl("javax.media.control.FrameGrabbingControl");
                Buffer buf = fgc.grabFrame();
                // Convert it to an image
                BufferToImage btoi = new BufferToImage((VideoFormat)buf.getFormat());
                Image img = btoi.createImage(buf);
//FOR SOME REASON, IMG IS NULL HERE SOMETIMES???
                processImage(img);
try{Thread.sleep(1000);}
catch(InterruptedException ie) {ie.printStackTrace();}
public void processImage (Image img){
//STUB
}

As nobody answered to your question yet, I am just telling about another possibility to connect to a camera from a java application. The Morena Image Acquisition Frame is a commmercial package (with a trial version) http://www.gnome.sk, which enables you to connect to a camera or scanner from a java application in a very intuitive way. It can help much if you do not need to display live video or get many images in a short time interval.
If you just want to see how Morena works with your scanner or camera:
- java (1.2 or higher for Windows, 1.3 or higher for Mac OS X) has to be installed on your computer
- a scanner or camera has to be installed on your computer
- download the trial package from http://www.gnome.sk
- unzipp it
- go to the examples directory of the unzipped package
- in Windows: doubleclick the runExampleShow.bat
- in MacOS:
    - open the Terminal window
    - change the working directory to the examples
    - run .sh file (type ExampleShow.sh or sh ExampleShow.sh)
This will pop up the Twain Source Selection user interface. There, all your scanners and cameras which do have a twain driver should be listed. (About 90% of scanners and cameras on the market do have a twain driver for Windows, only a few do have a twain driver for MacOS.) Select one of them. The user interface of the selected scanner (camera) will appear. Confirm the scanning (you can set the scanning parameters first). The scanned image will be displayed in a separate window. To end the application, close that window.
Running different examples, you can test scanning with hidden UI, saving the scanned image, using ADF, taking images at regular intervals (ExampleCamera) ...
If there is any problem, do not hesitate to inquire about it at the technical support, email: [email protected] .

Similar Messages

  • Does enyone know how to grabb frames using JMF

    can u please help me , if enyone knows
    how to grabb frames from .AVI file using JMF and
    also
    how to save those frames as JPEG in to HDD .

    Take a look at this
    http://java.sun.com/products/java-media/jmf/2.1.1/solutions/JVidCap.html

  • RTSP Bug in JMF?

    Hi Forum,
    I try to display a streamed video using JMStudio and RTSP.
    The streaming-server first sends a SDP-Packet in response of my request:
    ## outgoing msg:
    ## DESCRIBE rtsp://10.128.19.26/input1 RTSP/1.0
    CSeq: 113
    Accept: application/sdp
    User-Agent: JMF RTSP Player Version 2.1.1e
    ## incoming msg:
    ## RTSP/1.0 200 OK
    CSeq: 113
    Date: Fri, Jan 13 2006 13:08:24 GMT
    Content-Base: rtsp://10.128.19.26:7070/input1/
    Content-Type: application/sdp
    Content-Length: 406
    v=0
    o=- 1137084335764232 1 IN IP4 10.128.19.26
    s=Streamed by SISTORE_SXCX
    i=info
    t=0 0
    a=tool:LIVE555 Streaming Media v2006.01.04
    a=type:broadcast
    a=control:*
    a=source-filter: incl IN IP4 * 10.128.19.26
    a=rtcp:unicast reflection
    a=range:npt=0-
    a=x-qt-text-nam:Streamed by SISTORE_SXCX
    a=x-qt-text-inf:info
    m=video 0 RTP/AVP 96
    c=IN IP4 0.0.0.0
    a=rtpmap:96 H263-1998/90000
    a=control:track1In debugging mode i can see, that the range-attribute makes trouble in JMF.
    The parser expects something like this:
    a=range:npt=0-XSince the X is missing in the response of the server JMF crashes.
    But the X is not nessecary according to the specification of RTSP.
    Has anyone a workaround or an alternative to JMF?
    I could fix the problem in source code of my own, but we need this for a commercial product
    and SUN's licence doesn't accept changes of the library.
    thanks

    I don't think its a bug.
    Don't forget, JMF is only a "Reference
    Implementation".
    You need to implement your own RTSP code.
    You can use suns jmf RTSP as interfaces.
    I have done lots of debugging, at the point you are
    at.
    The only thing from what I remember, is that the
    stream is not passed to the player, so it does not
    play.Hi, mercury.
    Could you share your experience about your own RTSP code.
    Thanks.

  • TIFF JPEG conversion bug

    built-in JPEG converter, when used to send TIFF files to a .Mac screensaver or when used to export TIFF files to JPEG, results in distorted images on certain kinds of TIFF files, resulting in portions of the image displayed in vertical stripes across the screen... this seems to happen mostly to landscape-oriented photos which were scannned from 8x10 prints at 48-bit 600dpi (5960x4699) with a file size around 100MB... but does not occur on similar scans in portrait mode (4699x5899)... indicating a possible horizontal resolution limit around 5000?
    tested these same problem files with GraphicConverter and the resulting JPEGs did not have this problem

    OK, it's not loading the file that I'm having problems with, it's in the encoding:
    JAI.create( "encode", image, bos, format, null ) ;If I change the format to encode it as a TIFF file it returns the whole image. But I need to get it in a JPG or PNG format. Anyone have any ideas?
    Thanks

  • Question  linux jmf

    code:
    stream = ((NewReceiveStreamEvent) evt).getReceiveStream();
    tmp_ds = stream.getDataSource();
    Player player = Manager.createRealizedPlayer(tmp_ds); //here exception
    FrameGrabbingControl fgc = (FrameGrabbingControl) player.getControl("javax.media.control.FrameGrabbingControl");
    javax.media.Buffer buffer = fgc.grabFrame();           
    BufferToImage bufferToImage=new BufferToImage((VideoFormat)buffer.getFormat());
    Image image=bufferToImage.createImage(buffer);
    error message:
    javax.media.NoPlayerException: Error instantiating class: com.sun.media.content.unknown.Handler : java.awt.HeadlessException:
    No X11 DISPLAY variable was set, but this program performed an operation which requires it.
    at javax.media.Manager.createPlayerForSource(Manager.java:1502)
    at javax.media.Manager.createPlayer(Manager.java:500)
    at javax.media.Manager.createRealizedPlayer(Manager.java:579)
    at MulServerProcess.createTransmitter(MulServerProcess.java:374)
    at MulServerProcess.update(MulServerProcess.java:286)
    at com.sun.media.rtp.RTPEventHandler.processEvent(RTPEventHandler.java:62)
    at com.sun.media.rtp.RTPEventHandler.dispatchEvents(RTPEventHandler.java:96)
    at com.sun.media.rtp.RTPEventHandler.run(RTPEventHandler.java:115)
    add "export DISPLAY=localhost:0" to file " /etc/profile" ,but nothing happen!

    System.setProperty("java.awt.headless", "true"); add code
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    System.out.println("Headless mode: " + ge.isHeadless()); the answer is true;
    error message:
    javax.media.NoPlayerException: Error instantiating class: com.sun.media.content.unknown.Handler : java.awt.HeadlessException
    at javax.media.Manager.createPlayerForSource(Manager.java:1502)
    at javax.media.Manager.createPlayer(Manager.java:500)
    at MulServerProcess.createTransmitter(MulServerProcess.java:393)
    at MulServerProcess.update(MulServerProcess.java:292)
    at com.sun.media.rtp.RTPEventHandler.processEvent(RTPEventHandler.java:62)
    at com.sun.media.rtp.RTPEventHandler.dispatchEvents(RTPEventHandler.java:96)
    at com.sun.media.rtp.RTPEventHandler.run(RTPEventHandler.java:115)
    Re: Headless exception in AIX using JMF2.1.1
    This question is the same as me. But it is still not solved.
    Is this a bug of JMF in Linux ?

  • Crop operation not working in JAI 1.1.3?

    The "crop" operation seems to be broken in JAI 1.1.3 (at least for Windows):
    When cropping an image, the values for x and y are ignored and the new image is always the part from the upper left corner of the original image.
    In JAI 1.1.2 this worked correctly.
    Code to reproduce the problem (call program with old and new filename as parameters):
    The program should cut out an image with half the height and width from the middle of the original image.
    public static void main(String[] args) {
    // load image
    ParameterBlock loadPB = new ParameterBlock();
    loadPB.add(args[0]);
    RenderedOp image = JAI.create("fileload", loadPB);
    // crop image
    int width = image.getWidth();
    int height = image.getHeight();
    int newWidth = width / 2;
    int newHeight = height / 2;
    ParameterBlock pb = new ParameterBlock();
    pb.addSource(image);
    pb.add((float)(width - newWidth)/2);
    pb.add((float)(height - newHeight)/2);
    pb.add((float)newWidth);
    pb.add((float)newHeight);
    RenderedOp cropped = JAI.create("crop", pb, null);
    // save image
    ParameterBlock savePB = new ParameterBlock();
    savePB.addSource(cropped);
    savePB.add(args[1]);
    savePB.add("jpeg");
    JAI.create("filestore", savePB);
    }

    I also did that. I checked out if any crop had been done, and if so, save as BufferImage.
         public void save(String destinationFilename) {
              if (workaroundJPEG) {
                   //Workaround for JAI JPEG saving bug of no tile support (crop problems)
                   final int QUALITY = 75;
                   BufferedImage bufferedImage = objImage.getRendering().getAsBufferedImage();
                   try {
                        FileOutputStream fos = new FileOutputStream(destinationFilename);
                        BufferedOutputStream bos = new BufferedOutputStream(fos);
                        JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(bos);
                        JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bufferedImage);
                        param.setQuality(QUALITY / 100.0f, false);
                        encoder.setJPEGEncodeParam(param);
                        encoder.encode(bufferedImage);
                        bos.close();
                        workaroundJPEG = false;
                   } catch (IOException e) {
                        // handle errors
              } else {
                   JAI.create("filestore", objImage, destinationFilename, "JPEG", null);
         }Each time I do a crop operation I set the workaroundJPEG to true.

  • Export to Flash and keep the file size small!

    Clearly Keynote has a major bug when exporting to Flash. The files become very large, about 10x larger then the combined size of the JPEG's inserted. Earlier today I discovered how to get around this issue, albeit a far from perfect solution. Simply open each picture used in Photoshop and use the "save for web" menu. Save each image as GIF, 128 colors and rebuild the Keynote presentation. Although a color rich picture saved as GIF versus a reasonable compressed JPEG is x 3 or x 4 times larger the end result when exporting the Keynote to Flash is substantially smaller. Apparently Keynote exports to Flash without adding size when GIF's are used. Apple, please fix this "JPEG export" bug!

    Hi Gopal,
    You can get the components in your internal table using the below code-
    lo_struc_descr ?= cl_abap_typedescr=>describe_by_data( <fs_line> ).
        lt_components = lo_struc_descr->get_components( ).
    * Insert the component names in the start of the file
        LOOP AT lt_components INTO ls_components.
          IF lv_string IS INITIAL.
            lv_string = ls_components-name.
          ELSE.
            CONCATENATE lv_string ls_components-name INTO lv_string
            SEPARATED BY cl_abap_char_utilities=>horizontal_tab.
          ENDIF.
        ENDLOOP.
    Here <fs_line> is a work area. Basically we are getting all the fields in the internal table and writing their names in the start of the file.
    Hope it helps.
    Regards,
    Ravi

  • Where is the audio in TV / Video Cards???

    Hello boyz!
    I am developing a little framework over jmf to make life easier to java developers who want to use media in their apps.
    Now i am developing a Capturer class that is configured with an audio and video device and their capture formats.
    To a webcam and the soundcard works fine. I get a datasource from each device, if i have both, i make a merged datasource...
    But how works a videocard or tvcard? In the config of my class the video_device and audio_device will be the same, but later, how works the audio? Will i get a only datasource from the device with 2 streams? or how?
    Thanks in advance!
    jcpa1

    As for TV capture sound, should be same principle as your webcam or soundcard.In my machine i have a webcam (video_device), a soundcard(audio_device) and a microphone in the webcam.
    For the audio, capturemanager only shows: javasound and directsound (i suppose because i am in windows) and both are only for the soundcard, i cant select the microphone of the webcam :-(
    So i would like hear the experience of a user who has a tv or video card.
    How much easier can jmf get? if you know java, your sure be easily able to pick up jmf.To domine jmf you need to know about media formats, events, concurrency, and networking (if you want to send/receive) and later fight against the poor documentation and bugs of jmf.
    So, i suppose if you only need to incorpore simple media tasks in your app you wont to study all previous topics.
    Greetings.

  • VBR MP3 seeking

    Is there a way to make vbr seeking accurate?
    I have a JSlider to change media time with pl.setMediaTime(new Time((double)time)); where time is a position of a JSlider. It works fine with CBR files but with vbr it sets wrong time. Playback does not crush, but getMediaTime() returns longer time. For example it says that song played for 9 minutes instead of 7 minutes. Everyting's ok if I don't change position.
    Is it a bug of JMF or it can be fixed?

    Anyone find a solution to this? I am using JMF to mix two MP3 sources with link players. Works fine and the sources are in sync... until I try to seek to a specific media time, then they are badly out of sync. After much fooling around, my conclusion is that setMediaTime on a VBR mp3 source is broken.

  • My JPEGS are no longer being copied over to Finder.  Only a random fraction are copied.  It use to work perfect.  Is there a bug in the updated versions of iPhoto?

    My JPEGS are no longer being copied over to Finder.  Only a random fraction are copied.  It use to work perfect.  I can move them 4 or 5 at a time, but it is very time consuming.    Is there a bug in the updated versions of iPhoto?

    OK - here is what I've done in the past.  As I want to be able to save my photos on  a DVD that can be read by both a PC and a Mac, I am burning them in Finder.  I start by downloading into IPhoto.  I'll flag and edit the ones I want to print or post to the web.  After that I want to take all the keepers and move them from IPhoto to various files I create in the document  section of Finder.  I've done it both ways in the past, copy and paste or just drag over, all the files would transfer over.  Now there may be dozens of pictures that do not move over - very random, in one case there were only 6 photos and the 3 vertical ones did not copy over.
    I'm wondering if this is a software issue or if there is just too much data being moved around.  FYI there are 2 Nikon cameras I use and the files from both do this.
    Thanks

  • DW CS5 Image preview jpeg bug?

    Hi
    I've noticed that when placing .psd files in DW CS5, the predicted file size stops increasing once I get to around 80% quality. Normally there would be a huge increase in file size between 90% - 100%, but the file size remains the same (apparently), while still reporting that the quality has increased. Obviously this can't be true, and this didn't happen in older versions. Anyone else encountered the problem? I know you wouldn't normally use high quality images, but I run DW training courses, and it's important to see an accurate representation of file size v. quality in terms of demonstrating how jpeg works.
    Paul Greenstein

    Hi Beth
    Good, I'm glad it isn't just me getting this. By the way, I've noticed that the same thing happens when applying Image Settings to existing JPEGs.
    I would personally usually use Photoshop Save For Web for my own projects, but during a basic Dreamweaver course I don't assume that students have the rest of the Creative Suite back at work, so I generally tend to not go into Photoshop. In any case, being able to optimise images internally is a worthwhile feature I think.
    I'll send the bug report.
    Thanks for your response
    Paul

  • Bug with JPEGs in Notes.

    I can't find anywhere else to submit this, so...
    When placing JPEG files within an iPod Classic's Notes, the files (when viewed) are always scaled to a maximum of 320x216px, so that they fit on the screen. (Fun fact: the title bar is exactly 20px high, and when viewing images in Notes, a 4px-high strip of space at the bottom of the screen is reserved for... absolutely nothing.)
    Armed with this information, I attempted to make some files that fit the iPod's screen perfectly when viewed from Notes -- that is, some JPEGs that are exactly 320x216px.
    Problem is, the iPod has some kind of bug in its resizing algorithm. Attempting to view a JPEG Note that is exactly 320x216px will cause the iPod's OS to spontaneously and forcibly reboot, as if you had held Menu+Select. The image becomes viewable if either of its dimensions are changed by at least one pixel, but since the iPod's resizing function is absolutely dreadful, this is far from a desirable solution. The bug, then, is that images that don't need resizing crash the iPod (ten bucks says it's a divide-by-zero error resulting from unwise coding shortcuts).
    My question is: how do I report this to Apple? I can't seem to find a bug report form anywhere. (I also Googled the problem extensively in a fruitless attempt to find a workaround; apparently, I am the first human being to have ever experienced this problem.)
    On a side note: if anyone else is experiencing this problem, here are a few (and probably the only) possible workarounds. (And this is the other reason I'm posting it: to make the issue Googleable.)
    1. Resize the image, defying your perfectionism and leaving the image's quality in the hands of the iPod's terrible resizing algorithm.
    2. Find Apple's apparently non-existent iPod bug report form, report the bug, and wait for a patch... A patch that probably won't be made, because almost everyone has an iTouch now, and the iClassic is so 2008. (sigh)
    3. Give up, and put the files in your Photos even though they should logically be grouped in and accessed under Notes. (Photos can be 320x420px (a perfect fit for full-screen images) without crashing the iPod.)
    4. Hack the iPod's firmware and fix the glitch yourself, because you're just that hardcore.

    Yes, I had the same problem. Originally, I just ignored the missing icons - I didn't change the preferences that often anyway. Then I tried changing the --with-appspath compiletime option since I was recompiling anyway (with a patch that removes GNUstep menus from the alt-tab switch panel), but appspath doesn't seem to be used anymore.
    Today, I worked out a solution. Placing the binary in same directory as the icons makes WPrefs display its icons again. If you don't want to rebuild the package, you can copy /usr/share/WPrefs/ to somewhere in your $HOME, and copy /usr/bin/WPrefs into your copy of the WPrefs directory. You then, of course, have to make sure you launch WPrefs from this copy of the binary, not from /usr/bin/WPrefs.
    The somewhat cleaner solution is to rebuild the pkg with the following code added right after the "make DESTDIR=$startdir/pkg install" line in the PKGBUILD:
    # help WPrefs find its resources
    cd $startdir/pkg/usr
    mv bin/WPrefs share/WPrefs/WPrefs
    echo -e '#!/bin/shncd /usr/share/WPrefsnexec ./WPrefs' > bin/WPrefs
    chmod 755 bin/WPrefs

  • Problem with  M-JPEG by using JMF and JPEGCodec .

    Hi, there,
    I want to implement a M-JPEG using JMF and JPEGCodec, is that possible?(I already been trapped)
    My problem is I have a video clip which is a AVI file, the video format is following:
    Video format: RGB, 160x120, FrameRate=14.9, Length=57600, 24-bit, Masks=3:2:1, P
    ixelStride=3, LineStride=480, Flipped.
    I already convered a frame to an Image object(video format with JPEG and CVID doesn't work) ,
    I can also convert this Image back as a Buffer, It works fine with me .But to use JPEGCodec( provided by com.sun.image.codec.jpeg ) I need to convert an Image to a BufferedImage, I use the following defination:
    BufferedImage   bImage = new BufferedImage(frameImage.getWidth(null), frameImage.getHeigh(null),BufferedImage.TYPE_INT_RGB); It seems work, But when I use JPEGImageEncoder to encoder this bImage and save as a jpg file,
    everything is black .
    I also need to cast BufferedImage to an Image: frameImage = (Image) bImage; then I convert frameImage back to Buffer.My video clip still running , but every frame now became black .
    can someone help me? thanks in advance.

    I solved this problem . But I met a new problem.
    I converted the above video clip into a JPEG and I want to create a DataSink for it. the messege is:
    Video format: JPEG, 160x120, FrameRate=12.0, Length=3574
    - set content descriptor to: AVI
    - set track format to: JPEG
    Cannot transcode any track to: JPEG
    Cannot create the DataSink: javax.media.NoDataSinkException: Cannot find a DataS
    ink for: com.sun.media.multiplexer.RawBufferMux$RawBufferDataSource@2b7eea
    Transcoding failedHope some Java Experts can help me.
    Regards.

  • Bug: RAW+JPEG Pairs import setting affects movie imports

    Hi,
    I want to exclude JPEG duplicates during import, but if I set RAW+JPEG Pairs to "RAW files only", then movie files are not imported. The only way I can get movie files imported is to import both RAW and JPEG. Is there a workaround for this bug?

    Import the stills and movies separately and change the setting between imports.
    If you feel this is a bug report it using Aperture->Provide Aperture Feedback

  • Here is the source code to JMF Webcam app + saves jpeg

    Since so many people ask for this code, but never get it, I figured I'd repost it. I didn't write it, but I added the jpeg saving part, and modified it for my device, which you will have to do to get it to work. Just go into JMFRegistry and get the device name from your webcam and then edit the code. Also, keep in mind that some webcams don't work with JMF. You have to have a webcam that supports VFW or WDM interface.
    And here's the code:
    import javax.swing.*;
    import javax.swing.event.*;
    import java.io.*;
    import javax.media.*;
    import javax.media.format.*;
    import javax.media.util.*;
    import javax.media.control.*;
    import javax.media.protocol.*;
    import java.util.*;
    import java.awt.*;
    import java.awt.image.*;
    import java.awt.event.*;
    import com.sun.image.codec.jpeg.*;
    public class SwingCapture extends Panel implements ActionListener
      public static Player player = null;
      public CaptureDeviceInfo di = null;
      public MediaLocator ml = null;
      public JButton capture = null;
      public Buffer buf = null;
      public Image img = null;
      public VideoFormat vf = null;
      public BufferToImage btoi = null;
      public ImagePanel imgpanel = null;
      public SwingCapture()
        setLayout(new BorderLayout());
        setSize(320,550);
        imgpanel = new ImagePanel();
        capture = new JButton("Capture");
        capture.addActionListener(this);
        String str1 = "vfw:Logitech USB Video Camera:0";
        String str2 = "vfw:Microsoft WDM Image Capture (Win32):0";
        di = CaptureDeviceManager.getDevice(str2);
        ml = di.getLocator();
        try
          player = Manager.createRealizedPlayer(ml);
          player.start();
          Component comp;
          if ((comp = player.getVisualComponent()) != null)
            add(comp,BorderLayout.NORTH);
          add(capture,BorderLayout.CENTER);
          add(imgpanel,BorderLayout.SOUTH);
        catch (Exception e)
          e.printStackTrace();
      public static void main(String[] args)
        Frame f = new Frame("SwingCapture");
        SwingCapture cf = new SwingCapture();
        f.addWindowListener(new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
          playerclose();
          System.exit(0);}});
        f.add("Center",cf);
        f.pack();
        f.setSize(new Dimension(320,550));
        f.setVisible(true);
      public static void playerclose()
        player.close();
        player.deallocate();
      public void actionPerformed(ActionEvent e)
        JComponent c = (JComponent) e.getSource();
        if (c == capture)
          // Grab a frame
          FrameGrabbingControl fgc = (FrameGrabbingControl)
          player.getControl("javax.media.control.FrameGrabbingControl");
          buf = fgc.grabFrame();
          // Convert it to an image
          btoi = new BufferToImage((VideoFormat)buf.getFormat());
          img = btoi.createImage(buf);
          // show the image
          imgpanel.setImage(img);
          // save image
          saveJPG(img,"c:\\test.jpg");
      class ImagePanel extends Panel
        public Image myimg = null;
        public ImagePanel()
          setLayout(null);
          setSize(320,240);
        public void setImage(Image img)
          this.myimg = img;
          repaint();
        public void paint(Graphics g)
          if (myimg != null)
            g.drawImage(myimg, 0, 0, this);
      public static void saveJPG(Image img, String s)
        BufferedImage bi = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = bi.createGraphics();
        g2.drawImage(img, null, null);
        FileOutputStream out = null;
        try
          out = new FileOutputStream(s);
        catch (java.io.FileNotFoundException io)
          System.out.println("File Not Found");
        JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
        JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bi);
        param.setQuality(0.5f,false);
        encoder.setJPEGEncodeParam(param);
        try
          encoder.encode(bi);
          out.close();
        catch (java.io.IOException io)
          System.out.println("IOException");

    Hi William,
    I've tried this code but I always get an null fgc with the following line.
    FrameGrabbingControl fgc = (FrameGrabbingControl)player.getControl("javax.media.control.FrameGrabbingCotrol");
    So the player returns always null. The other thigns seem to be fine. I can view the image in the application but when I click capture it throws a Null Pointer Exception because fgc is null.
    I am using Logitech QuickCam, USB, Win2k, jdk 1.3.1, JMF 2.1.1
    Can you help me?
    thanx,
    Philip
    Since so many people ask for this code, but never get
    it, I figured I'd repost it. I didn't write it, but I
    added the jpeg saving part, and modified it for my
    device, which you will have to do to get it to work.
    Just go into JMFRegistry and get the device name from
    your webcam and then edit the code. Also, keep in mind
    that some webcams don't work with JMF. You have to
    have a webcam that supports VFW or WDM interface.
    And here's the code:
    import javax.swing.*;
    import javax.swing.event.*;
    import java.io.*;
    import javax.media.*;
    import javax.media.format.*;
    import javax.media.util.*;
    import javax.media.control.*;
    import javax.media.protocol.*;
    import java.util.*;
    import java.awt.*;
    import java.awt.image.*;
    import java.awt.event.*;
    import com.sun.image.codec.jpeg.*;
    public class SwingCapture extends Panel implements
    ActionListener
    public static Player player = null;
    public CaptureDeviceInfo di = null;
    public MediaLocator ml = null;
    public JButton capture = null;
    public Buffer buf = null;
    public Image img = null;
    public VideoFormat vf = null;
    public BufferToImage btoi = null;
    public ImagePanel imgpanel = null;
    public SwingCapture()
    setLayout(new BorderLayout());
    setSize(320,550);
    imgpanel = new ImagePanel();
    capture = new JButton("Capture");
    capture.addActionListener(this);
    String str1 = "vfw:Logitech USB Video Camera:0";
    String str2 = "vfw:Microsoft WDM Image Capture
    ure (Win32):0";
    di = CaptureDeviceManager.getDevice(str2);
    ml = di.getLocator();
    try
    player = Manager.createRealizedPlayer(ml);
    player.start();
    Component comp;
    if ((comp = player.getVisualComponent()) !=
    )) != null)
    add(comp,BorderLayout.NORTH);
    add(capture,BorderLayout.CENTER);
    add(imgpanel,BorderLayout.SOUTH);
    catch (Exception e)
    e.printStackTrace();
    public static void main(String[] args)
    Frame f = new Frame("SwingCapture");
    SwingCapture cf = new SwingCapture();
    f.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    playerclose();
    System.exit(0);}});
    f.add("Center",cf);
    f.pack();
    f.setSize(new Dimension(320,550));
    f.setVisible(true);
    public static void playerclose()
    player.close();
    player.deallocate();
    public void actionPerformed(ActionEvent e)
    JComponent c = (JComponent) e.getSource();
    if (c == capture)
    // Grab a frame
    FrameGrabbingControl fgc =
    fgc = (FrameGrabbingControl)
    player.getControl("javax.media.control.FrameGrabbingCo
    trol");
    buf = fgc.grabFrame();
    // Convert it to an image
    btoi = new
    = new BufferToImage((VideoFormat)buf.getFormat());
    img = btoi.createImage(buf);
    // show the image
    imgpanel.setImage(img);
    // save image
    saveJPG(img,"c:\\test.jpg");
    class ImagePanel extends Panel
    public Image myimg = null;
    public ImagePanel()
    setLayout(null);
    setSize(320,240);
    public void setImage(Image img)
    this.myimg = img;
    repaint();
    public void paint(Graphics g)
    if (myimg != null)
    g.drawImage(myimg, 0, 0, this);
    public static void saveJPG(Image img, String s)
    BufferedImage bi = new
    new BufferedImage(img.getWidth(null),
    img.getHeight(null), BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = bi.createGraphics();
    g2.drawImage(img, null, null);
    FileOutputStream out = null;
    try
    out = new FileOutputStream(s);
    catch (java.io.FileNotFoundException io)
    System.out.println("File Not Found");
    JPEGImageEncoder encoder =
    r = JPEGCodec.createJPEGEncoder(out);
    JPEGEncodeParam param =
    m = encoder.getDefaultJPEGEncodeParam(bi);
    param.setQuality(0.5f,false);
    encoder.setJPEGEncodeParam(param);
    try
    encoder.encode(bi);
    out.close();
    catch (java.io.IOException io)
    System.out.println("IOException");

Maybe you are looking for

  • Product ID is not getting updated in SC Goods /Service field

    Hi Gurus, While creating shopping carts in EBP, we are able to find the Product ID from the Good/Service find option, but when we select the Product ID in the search, it's not getting updated in the SC Goods/Service field.Also when we try to find the

  • How to permanently boot up in verbose mode?

    Hi, I want to always boot up OS X Mavericks (10.9.2) in verbose mode (debug mode) as I pressed Cmd+V everytime. I remember an old command which I used on Snow Leopard for doing this: « sudo nvram boot-args="-v" » but I don't know if it's still valid

  • Recording from Reel to Reel

    I am trying to record from an old reel to reel machine to my MacBook. I have a Griffin iMic and have tried using GarageBand to record the audio. There are 2 output connection on the Reel to Reel machine -- output to Amp and output to Speaker. I have

  • How to Edit an Existing Email in Apple Mail

    Its rather quite easy: Simple go to the Message menu and select Redirect. Then redirect the email to yourself after making edits. This is useful if you want to keep the email intact, but to edit the subject line to make it easier to identify the cont

  • Pls Help Clarify

    Hello All, I need help on the below. I have to setup a payroll for a company and it has 3 locations which are seperately handled by different people but all under one Business Group. Please let me know 1. If i would need to create just one responsibi