SAVING PICTURES FROM WEBCAM

Hi, there!!
I need to save frames from a Web Cam... How could I
do that???
Thank You very much!!

Here's how I did it:
The important thing to notice is that there's a few extra lines, this code actually grabs the frame, saves it to a file as a JPEG, then uploads that file to a webserver (but all of that happens in another class)
Hope this helps!!!
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.event.*;
import com.sun.image.codec.jpeg.*;
import java.net.*;
public class CaptureWindow extends JPanel 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;
     Uploader tf = new Uploader();
     private javax.swing.Timer timer;
     public static int delayTime = 30000;
     public String filename = "Testing.jpg";
     public boolean active = true;
     public CaptureWindow() {
          createFrame();
     public CaptureWindow(int del) {
          delayTime = del;
          createFrame();
     public void createFrame() {
          setLayout(new BorderLayout());
          setSize(320,550);
          imgpanel = new ImagePanel();
          capture = new JButton("Capture");
          capture.addActionListener(this);
          DeviceTest.detectDevices();
          timer = new javax.swing.Timer(delayTime, new TimerListener());
          //di = CaptureDeviceManager.getDevice("vfw:3Com HomeConnect Digital Camera AVI Driver:0");
          di = DeviceTest.getVideoDevice();
          //System.out.println(di);
          //test of line numbers
          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();
          this.startUpload();
     public void startUpload() {
          if (active)
               timer.start();
     public void stopUpload() {
          if (timer.isRunning())
               timer.stop();
     public static void playerclose(){
          player.close();
          player.deallocate();
     public void CaptureIt() {
          FrameGrabbingControl fgc = (FrameGrabbingControl) player.getControl("javax.media.control.FrameGrabbingControl");
          buf = fgc.grabFrame();
          btoi = new BufferToImage((VideoFormat)buf.getFormat());
          java.awt.image.BufferedImage img = (java.awt.image.BufferedImage)btoi.createImage(buf);
          try {
               File file = new File(filename);
               FileOutputStream out = new FileOutputStream(file);
               JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
               JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(img);
               param.setQuality(0.7f, false);
               encoder.setJPEGEncodeParam(param);
               //encoder.encode(buffImg);
               encoder.encode(img);
               out.close();
               } catch (Exception ex) { 
                    ex.printStackTrace();
               tf.main(filename);
               imgpanel.setImage(img);
     public void actionPerformed(ActionEvent e){
          JComponent c = (JComponent) e.getSource();
          if (c == capture) {
          CaptureIt();               
     class TimerListener implements ActionListener {
          public void actionPerformed(ActionEvent evt) {
               CaptureIt();
     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);
}

Similar Messages

  • Can't see my saved picture from the internet

    hi guys, i have one serious problem, i cant see my picture that has been saved before from the internet. so when i got a picture from google and i saved it, i cant find it in my "pictures" in the media categories on my playbook. do anyone knows where the playbook stores my saved picture from the internet? please help me T.T
    Solved!
    Go to Solution.

    hey entimp,thanks for your reply. but i found out that there are only "all pictures" and "wallpaper" within my pictures app, there isnt "downloads". what do you think??  

  • Saving pictures from email.

    When saving pictures to my iphone from an email the pictures show up very blurry & not as crisp & clean that they had looked in the email. Transfered pictures from my computer to my iphone look great. What is wrong with my pictures? & How can I get them to look good when I save them.
    Thanks,
    E

    I'm having this same problem and it has been going on for a couple of months now. Every time I try and save a picture from an email or the internet, it shows up very blurry on my iphone. This even happens from pictures that I saved from emails awhile ago; they used to be clear and sharp, now they are very blurry.
    Anyone out there have any ideas about this one??

  • Saving picture from email account

    can anyone let me know how to save pictures from your email to your phone? somebody sent me a picture that i would really like to place as my wallpaper - is the only way to accomplish this by saving the picture to iphoto and re-syncing? if there is a way to click on the picture in my email and save it, i would greatly appreciate the help . . .
    Thanks

    You can not save the photo from email on the phone, It is view only. The Picture would have to be saved to your computer then placed on to the phone.

  • Saving picture from safari

    I'm new to Mac. How do you save a picture from a webpage so that it will be a jpg file? I know you right click on the mouse if it were a PC, but how do you do it on a Mac? I haven't had a chance to get a mouse for my MacBook Pro, but I don't think that it should matter because there's no right click on Mac. I'd really appreciate it if someone can help me. Thanks!
    macbook pro   Mac OS X (10.4.9)  
    macbook pro   Mac OS X (10.4.9)  

    Hi
    Welcome to Apple Discussions and Mac Computing
    There are a few ways to save pictures from the web. The easiest is simply to click on the picture and drag it to the desktop. From there, you can move the file to any other location via the Finder.
    Right click on a MacBook - the unique trackpad of the notebook makes this rather easy. Go to System Preferences>Keyboard & Mouse>Trackpad to enable the "tap trackpad using two fingers for secondary click".
    Right click brings up a contextual menu. One command is to save image. Pressing the option key changes this to "save image as". You can rename the image, plus navigate to a specific location for saving it.
    Good way to familiarize yourself with OS X is to pick up a copy of Scott Kelby's book OS X Tiger: Killer Tips.

  • Trouble Saving Pictures From Email

    I am unable to save pictures that were sent as attachments.  Hen I tap on the picture, it gives me 3 options.  Open in Safari, Open in Chrome, Copy Image link.  I can save pics from the web.

    I'm having this same problem and it has been going on for a couple of months now. Every time I try and save a picture from an email or the internet, it shows up very blurry on my iphone. This even happens from pictures that I saved from emails awhile ago; they used to be clear and sharp, now they are very blurry.
    Anyone out there have any ideas about this one??

  • Saving pictures from bbm

    I have Z10 when I save a picture from a friends display at the BBM when I go to the picture folder I can't find it, I don't know where is it saved. Can any body help me with this issue
    Thanks

    When you save that picture from the friend's display, before saving it will show exactly where the file is being saved or allow you to change it. Note that location before you press SAVE.
    It could be //sdcard/photos, but may vary for you.
    1. If any post helps you please click the below the post(s) that helped you.
    2. Please resolve your thread by marking the post "Solution?" which solved it for you!
    3. Install free BlackBerry Protect today for backups of contacts and data.
    4. Guide to Unlocking your BlackBerry & Unlock Codes
    Join our BBM Channels (Beta)
    BlackBerry Support Forums Channel
    PIN: C0001B7B4   Display/Scan Bar Code
    Knowledge Base Updates
    PIN: C0005A9AA   Display/Scan Bar Code

  • No picture from webcam in Messages

    I am having a problem with Messages. It does not seem to want to accept the picture from my webcam. It was working just fine a few weeks ago, but suddenly it does not. My first assumption was that it is the web cam that is going. However, I have tried the webcam on my Windows laptop and it works there. I tried it with FaceTime on my Mac and that gets the picture from the webcam. However, with both Messages and Skype on the Mac, I get only a black screen for the image. Is there some setting that I am missing?

    I doubt this will help, but I don't have a better idea.
    Read this whole message before doing anything.
    Back up all data.
    Quit Messages if it’s running.
    Step 1
    Hold down the option key and select
    Go ▹ Library
    from the Finder menu bar. Move the following items from the Library folder to the Trash (either may not exist):
    Caches/com.apple.Messages
    Caches/com.apple.imfoundation.IMRemoteURLConnectionAgent
    Leave the Library folder open. Log out and log back in. Try Messages again. If it works now, stop here. Close the Library folder.
    Step 2
    If you still have problems, quit Messages again. Go back to the Finder and move the following item from the open Library folder to the Desktop:
    Messages
    Note: you are not moving the Messages application. You’re moving a folder named “Messages.”
    Test. If Messages now works, delete the Messages folder on the Desktop. Otherwise, quit Messages again. Put back the folder you moved, overwriting the newer one that may have been created in its place, and continue.
    Step 3
    In the Preferences subfolder, there may be several files having names that begin with any of the following strings:
    com.apple.iChat
    com.apple.imdsmsrecordstore
    com.apple.imessage
    com.apple.imservice
    Move them all to the Desktop. There may also be a file with the name "com.apple.imagent.plist". Move that to the Trash.
    Also in the Preferences folder, there's a subfolder named "ByHost". Open it and do the same thing.
    Log out and log back in. Test again. This time Messages should perform normally, but your settings will be lost. You may be able to put back some of the files you moved to the Desktop in this step. Relaunch and test after each one. Eventually you should find one or more that causes Messages to malfunction. Delete those files and recreate whatever settings they contained.
    If the issue is still not resolved, quit Messages again and put all the items you moved to the Desktop back where they were. You don’t need to replace the items you moved to the Trash. Stop here and post again.
    If you later decide that you don’t like the results of steps 2 and 3, you can undo them completely by quitting Messages and restoring the items you deleted in those steps from your backup.

  • Problems saving pictures from Facebook

    I recently downloaded the IOS 6 onto my iphone 4. I now cannot save pictures from the Live feed on Facebook like I use too. I can save pictures from safari and take screen shots still though. My coworker has a iphone 4s and she does not seem to have that problem. Hopefully someone else is experiencing this problem and can help me out. I tried deleting FB app and reinstalling, but it still does not work. Thank you for your time.

    I am having the same problem. Facebook asked me to allow access to my photos and I accidently declined it. Now I cannot change the settings anymore. I checked and there is no Photo option in the privacy settings. How did you guys manage to solve the problem? Thanks!

  • Saving pictures from facebook

    I used to save quotes/pictures from facebook, but now i cant...any help please!!!!

    Go to Settings>Privacy>Photos and make sure FaceBook is set to On.

  • Saving pictures from google.

    Why is it that when I hold down on a picture from google images, it no longer gives me the option to save picture?

    Maybe google blocked that option.

  • Losing saved pictures from a text?

    I saved the pictures I received from a text, and they save in a folder under my camera, but twice in the last 2 days they've been deleted. How can I get them to stay? And is there another place that they are saved? Or do I have to go into my camera every time? I have the incredible 2.

    Cobjones wrote:
    @thegreatone
    you really want that botb huh?
    I don't want to get too noticed but....
    YES!!

  • Saved pictures from the internet missing.

    Since downloading IOS8 I can't find pictures that I newley save from the internet. I clicked on two photos tonight and clicked the save photo option. When I went to the photo app they are nowhere to be found.

    right click, SAVE AS, choose download location on your Mac
    usually in the downloads folder
    Finder  > go > downloads

  • Saving pictures from web pages..is that possible

    Is it possible while viewing a picture on a web page..to save that image and send it to my email. I just got my iphone and Im not sure how to do that.??
    Thanks so much

    In a word, no.
    You cannot do so from a web page or with photos received via email.

  • Saving picture from email onto Itouch?

    Would anyone know how to save photo from an email onto the Itouch? According to the manual it said to hold down on the picture and hit save... Can't seem to find the save button.... Suggestions?

    Hi,
    The method you describe is correct.
    Do you have 2.0. Software? This is required.
    Dud.
    Message was edited by: Duddo

Maybe you are looking for

  • IPad video clips to iMac?

    How can I import videos onto my iMac iMovie from my iPad (without emailing it)? I Have iMovie '09 and an iPad 2.

  • FCP WONT LAUNCH!!!

    Searched this topic to no avail... infact all the information I found made the situation worse... I have: MacBookPro Tiger 10.4.7 Final Cut Studio One day, FCP 5.1.1 stopped opening. It would begin launching, the window opens to load but it would jus

  • How to simulate sms serviceS

    Hi there Currently I am working on J2ME project but I am stucked in SMS problem. How can I simulate sms sending and receiving to and from emulators. I want to send sms from my PC to emulator and receive sms form emulator. Could you please help me wit

  • Anyone else have blurry iphone 5 camera?

    I bought my iphone 5 a week or so ago. One day the camera decided to go blurry. Tried restarting phone and resetting but no luck. Woke up this morning and the problem had rectified itself. No problem now, but worried about it happening again in the f

  • CVP Call Server Logs

    Dear Members, Could someone help me by providing any good document related to the "CVP CALLSERVER LOGS" and "CVP VXMLSERVER LOGS" Regards, Senthil.