JMF - getting a webcam to take a picture!

Hi everyone,
I am looking for help with JMF please! I am having a lot of trouble with JMF trying to get a webcam to take a picture so that i can then use it fro comparision reasons.....
Hope somebody will be able to give me a push in the right direction, i would really appreciate it!!!
Thanks,
Pam
x

I found out that the exception occured because currentFormat was null.. I added a few more lines to the code which now works without any errors.
However i have a little problem. The picture taken is just black... I don't know why this is happening.
Here is the source.
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.media.*;
import javax.media.CaptureDeviceInfo;
import javax.media.CaptureDeviceManager;
import javax.media.control.FrameGrabbingControl;
import javax.media.format.VideoFormat;
import javax.media.util.BufferToImage;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGEncodeParam;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
import javax.media.control.FormatControl;
public class FrameCapture {
    static MediaLocator ml;
    static Player player;
    static Component videoScreen;
    static Buffer buf = null;
    static String str = null;
    static BufferToImage btoi = null;
    static BufferedImage bi = null;
    static Image frameImage = null;
    static String filename = null;
    static FormatControl formatControl = null;
    static Format currFormat = null;
    static VideoFormat currentFormat = null;
    public static void main(String[] args) {
        try {
            ml = new MediaLocator("vfw://0");
            player = Manager.createRealizedPlayer(ml);
            player.start();
            videoScreen = player.getVisualComponent();
            Frame frame = new Frame();
            frame.setBounds(10, 10, 300, 300);
            frame.add(videoScreen);
            frame.setVisible(true);
            FrameGrabbingControl fgc = (FrameGrabbingControl)player.getControl("javax.media.control.FrameGrabbingControl");
            if (fgc == null) {
                System.out.println("fgc == null");
            buf = fgc.grabFrame();
            if (buf == null) {
                System.out.println("buf == null");
            btoi = new BufferToImage((VideoFormat) buf.getFormat());
            if (btoi == null) {
                System.out.println("btoi == null");
            formatControl = (FormatControl)player.getControl ( "javax.media.control.FormatControl" );
            if (formatControl == null) {
                System.out.println("formatControl == null");
            currFormat = formatControl.getFormat();
            if (currFormat == null) {
                System.out.println("currFormat == null");
            currentFormat = (VideoFormat)currFormat;
            //VideoFormat currentFormat = (VideoFormat)buf.getFormat();
            if (currentFormat == null) {
                System.out.println("currentFormat == null");
            BufferedImage bi = new BufferedImage ( currentFormat.getSize().width,
                                                   currentFormat.getSize().height,
                                                   BufferedImage.TYPE_INT_RGB );
            Image image = btoi.createImage ( buf );
            Graphics2D g2 = bi.createGraphics();
            g2.drawImage ( image, null, null );
            FileOutputStream out = null;
            try
                filename = "myImage.jpeg";
                out = new FileOutputStream ( filename );
                JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder ( out );
                JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam ( bi );
                param.setQuality ( 1.0f, false );   // 100% high quality setting, no compression
                encoder.setJPEGEncodeParam ( param );
                encoder.encode ( bi );
                out.close();
            catch ( Exception e )
                System.out.println ("Error saving JPEG : " + e.getMessage());
                e.printStackTrace();
            player.close();
            player.deallocate();
        }catch(Exception e) {
            System.err.println("U r Stupid..: " + e.getMessage());
            e.printStackTrace();
}

Similar Messages

  • How do i take a picture with my built in webcam?

    hey guys
    i have a macbook pro with a built in web cam...im sure theres a way to take a pic with it...does anyone know how?
    it would also be nice if i wouldn't have to download another program to do this...
    is there anyway i can take a picture and have it has somehting like a .jpeg?
    thanks!

    Also start up iChat (this shows in the DOCK)
    It should let you click through the Start Up screens if you don't have a Screen name yet.
    Click on the Buddy Pic it currently shows for you.
    Select Edit pic.
    Press the Take Video Snapshot
    When you then select SET it will save this in
    Users/(your Account)/Library/Images/Recent iChat Pics
    Or you can go to the Video menu of iChat and Select TAke Snapshot and this will be saved to the DESKTOP but may need further work in a Graphics app to get just your head if that is what you are aiming at.
    8:31 PM Sunday; April 22, 2007

  • When I click on camera, I only get a blank screen. I used it earlier to take a picture.

    When I click on Camera, I only get a blank screen. I used it earlier to take a picture.  What is wrong?

    Start Firefox in [[Safe Mode]] to check if one of the add-ons is causing the problem (switch to the DEFAULT theme: Tools > Add-ons > Themes).
    * Don't make any changes on the Safe mode start window.
    See:
    * [[Troubleshooting extensions and themes]]
    * [[Troubleshooting plugins]]

  • When I take a picture with the flash on auto, I get a blue circle and no picture. When I turn the flash off the  picture comes out fine. What do I do to take a pic in low light

    When I take a picture with my iphone 4 and the flash is on I get a blue flash and a big blue screen with no pic. When I  turn the flash off the pics come out
    fine. I turn the flash on to take a pic in low light I just get a blue screen. How do I remedy this?

    Try a reset or restart of the device.
    If that doesn't work attempt a restore of the phone's iOS

  • When I attempt to apply a lens profile in the Develop module the only choices are for the Fujifilm X100/S/T even though in the Library module the EXIF data correctly shows the camera as the X-T1 and the precise lens used to take the picture. How do I get

    When I attempt to apply a lens profile in the Develop module the only choices are for the Fujifilm X100/S/T even though in the Library module the EXIF data correctly shows the camera as the X-T1 and the precise lens used to take the picture. How do I get the right profile available?

    First, the required profile needs to be present. LR 5.4 supports the X-T1 in terms of understanding its Raw format, but will not come with a profile for every lens which can be mounted onto that.
    A profile is made for each specific lens, as mounted on a certain camera. It can also be used with pictures taken on a different (reasonably similar) camera body than the one originally used during profiling. This is subject to the sensor format: you can employ a given lens profile made for full frame, on an image from a crop sensor behind the same lens - but not vice versa.
    Next, the image type needs to correspond to the image type which has been built into the profile: Raw, or non-Raw.
    Lightroom offers only profiles of the right type for the image(s) concerned. There are many more provided for correcting camera Raw, than for correcting camera JPG. That is also the case with additional profiles, e.g. those accessed via the Adobe lens profile downloader utility.
    Finally, in the event that there simply is no profile out there for a given lens, it is not particularly difficult (though a little tedious) for the end user to generate one, using a further Adobe utility which is downloadable as a package, including a range of checkerboard calibration targets, each of which needs to be printed at a stated physical size.

  • HT1688 When I take pictures using the front camera the photo saves as if it were flipped in the opposite direct. How do I get it to saved as the picture was originally taken?

    When I take pictures using the front camera the photo saves as if it were flipped in the opposite direct. How do I get it to saved as the picture was originally taken?

    If you are talking about landscape pictures, hold the phone so the camera is at the top and the volume buttons on the bottom. If you hold it with the volume buttons on the top, the camera is upside down.

  • I have an iPhone 4S-whenever I take a picture using the flash, all I get is a white blob-pictures without the flash are fine.  I tried using different cases, thinking a bounce off the case might be the problem, but the same thing happens.  Any suggestions

    I have an iphone 4s - whenever I take a picture using the flash, all I get is a white "blob".  Pictures without the flash are fine.  I thought the flash bouncing off the case might be the problem, but when I used different cases I still had the same problem.  Any suggestions?

    I have an iphone 4s - whenever I take a picture using the flash, all I get is a white "blob".  Pictures without the flash are fine.  I thought the flash bouncing off the case might be the problem, but when I used different cases I still had the same problem.  Any suggestions?

  • Why won't my camera work? I used the screen shot for the first time and since i did that every time i take a picture the shutter closes as though it's taking it but no picture gets taken...help! Any suggestions?

    Why won't my camera work? I used the screen shot for the first time and since i did that every time i take a picture the shutter closes as though it's taking it but no picture gets taken...help! Any suggestions?

    Hey briannagrace96,
    Welcome to Apple Support Communities! I'd check out the following article, it looks like it applies to your situation:
    iPod: Appears in Windows but not in iTunes
    http://support.apple.com/kb/ts1363
    You'll want to go through the following troubleshooting steps, and for more detail on each step follow the link to the article above:
    Try the iPod troubleshooting assistant:
    If you have not already done so, try the steps in the iPod Troubleshooting Assistant (choose your iPod model from the list).
    If the issue remains after following your iPod's troubleshooting assistant, follow the steps below to continue troubleshooting your issue.
    Restart the iPod Service
    Restart the Apple Mobile Device Service
    Empty your Temp directory and restart
    Verify that the Apple Mobile Device USB Driver is installed
    Change your iPod's drive letter
    Remove and reinstall iTunes
    Disable conflicting System Services and Startup Items
    Update, Reconfigure, Disable, or Remove Security Software
    Deleting damaged or incorrect registry keys
    Take care,
    David

  • Can this webcam take 'still' pictures to create a movie?

    We are interseted in purchasing a video camera for our son to make lego movies. The one used on youtube is a logicam 9000. I read that this is a 'webcam'. Can he take still pictures with this then play them back as a smooth movie? He is also interested in Effects LAb to create graphics. Does any one know anything about the compatability of these two? Thanks in advance.

    Ah, you mean a stop motion movie?  (take a still picture of the legos, move them slightly, take another still picture.)
    The webcam should work, but you may be better off with a good still picture camera (something that can focus up-close).  It's going to be all about the software you use to assemble the stills into a video - this is a pretty common task and there's lots of software that will do it, quite a bit of which will be free.
    *disclaimer* I am not now, nor have I ever been, an employee of Best Buy, Geek Squad, nor of any of their affiliate, parent, or subsidiary companies.

  • I have a EOS 7D , i need to be able to take indoor pictures of homes. I am a realtor. So getting a p

    i have a EOS 7D , i need to be able to take indoor pictures of homes. I am a realtor. So getting a picture of a small bedroom or bath is difficult.  what wide angle lens do you suggest. Price is a concern, i do not want to spend more thatn $500  I am a amature photographer, i do everything on Auto.
    Solved!
    Go to Solution.

    Agree with Cicopo, but would add that you can save some money by buying used.  I found a Canon 10-20mm used just looking around for 5 minutes.  Places to look include:
    Amazon
    Ebay (but be careful)
    Photography On The Net's forum page.  (You have to register to see the for sale items)
    Craigslist (though you could wait a LONG TIME for a particular lens to pop up in your particular area.
    The Canon has good IQ compared to most of the contenders, though it costs a bit more than the others.  On the other hand, IF your shots never get blown up more than a small inset image on a website, or a thumbnail on a home flyer, then you really don't need awesome IQ.  On the other hand, you own a 7D, which suggests you probably enjoy photography more than the average realtor taking shots of listings.  If that is the case, and you would get personal use out of it too, then maybe you want to get the best possible lens near your budget.
    Do avoid off-brand lenses that are manual focus only (Bower, Samyang, Rokinon, etc.) unless you feel comfortable doing MF on your camera.  You have to read the descriptions carefully to not miss that.
    Good luck!
    Scott
    Canon 6D, Canon T3i, EF 70-200mm L f/2.8 IS mk2; EF 24-105 f/4 L; EF-S 17-55mm f/2.8 IS; EF 85mm f/1.8; Sigma 35mm f/1.4 "Art"; EF 1.4x extender mk. 3; 3x Phottix Mitros+ speedlites
    Why do so many people say "fer-tographer"? Do they take "fertographs"?

  • Sony NEX 5n: I get a " camera error" message when I take a picture

    When I take a picture I get a "camera error" message. I have taken the battery out; tried turning the camera on and off; Checked the version of the firmware and I have 1.2 so it is up to date. Tried changing the memory card.

    Hello bobbi00! The camera error message is usually an indication that a shutter malfunction has occurred. If the error message appears often even after trying the steps you mentioned, the camera will require service.
    You can find repair information and initiate service for your camera on this link.

  • I am trying to take a picture of a web page and paste on a one drive powerpoint. I tryed pressing the print screen button, and pasting. But it is giving me message saying that my browser can not fine the clipboard, and I need to use the keyboard shortcuts

    I need to take a picture of a web page, insert it onto a powerpoint online, and crop the picture. I am pressing the print screen button, and right cliking paste. But I am getting the warning message saying that my browser can not use the clipboard, and I am unsure of how to take a picture, then paste it, and crop it all on to a power point.

    http://portableapps.com/apps/internet/firefox_portable/localization#legacy36

  • I got a canon EOS rebel T3 camera yesterday and it flashed orange and I can't take anymore pictures!

    So, yesterday I got a Canon EOS Rebel T3 and it was working perfectly fine and I was just getting the hang of it! But then all of a sudden i don't know/remember pressing anything and it flashed orange when I went to take a picture and it did it again and it wasn't the battery because the batterie was halfway and I don't know what to do... It doesn't make a noise or anything when I click the shutter button! Please help me I'm freaking out!

    Hold on don't send it anywhere until you:
    Remove the battery for 30 minutes or so. Make sure it is fully charged and reinsert it.
    Use a known good SD card.  <----very important
    Make sure you go into the menu and set everything back to factory defaults. (Check your manual)
    Make sure the dial on the top is set to the green square.
    Now try it again!  
    EOS 1Ds Mk III, EOS 1D Mk IV EF 50mm f1.2 L, EF 24-70mm f2.8 L,
    EF 70-200mm f2.8 L IS II, Sigma 120-300mm f2.8 EX APO
    Photoshop CS6, ACR 8.7, Lightroom 5.7

  • When I take a picture with my iphone, the date does not show when I down load the picture. Is there a way to program this?

    when I take a picture with my iphone, the date is not downloaded to my picute. Is there a way to get the date put on my pictures.

    Dropbox "Camera upload" option just rename the files and looks like this.

  • How to take a picture from a video file

    Is there a way to take a picture of video clip from the web?  I am trying to pull a pic of a video file, a single frame. Is there an app, or a really easy way to crop and save a photo to my library?

    Pause the video where you want the clip then use shift+command+4 to get a cross hair selector and drag that across the part of the screen you want to capture, it will be saved as Screenshot_date_time to your Desktop

Maybe you are looking for