Corrupted image in applet from web cam

Hi there I created a little webcam server application that listens to port 8080 for requests, then displays an image. The image is jpeg encoded frame grabbed from a logitech web cam using the java media framework. I got the code from this forum.
I have tried it across a 56kb modem on four different computers. On three the applet displays the images without problems. On the fourth the image is corrupted like it didn't receive all the data.
Anyone have any idea why this occurs in one and not the others
Here's some of the source
The applet just uses getImage( http://[host]:8080 )
and media tracker with a thread sleeping for a second
public class WebCamServer extends JFrame
     // class variables
     private HttpServer webserver;
     private int port = 80;
     private ServerSocket server;
     private ImageIcon gfr;
     private Color backcolour = new Color( 255, 255, 255 );     
     private Player player = null;
     private MediaLocator ml = null;
     private JPanel campanel = null;
     public boolean active = false;
     public Buffer buf = null;
     public VideoFormat vf = null;
     public BufferToImage btoi = null;
     public Image img = null;
public WebCamServer()
          // initialise Frame with this heading and font
          super( "eyespyfx - Web Cam Server" );
          setFont( new Font( "Verdana", Font.PLAIN, 12 ) );
          // initialise web server
          startServer();
          // set up ServerSocket to listen for requests on port 8080
          try
               server = new ServerSocket( 8080 );
          catch( IOException e )
               System.err.println( "Server Socket Error" );
               System.err.println( e.getMessage() );
               shutdown();
          // set frame icon to gfr.gif
          gfr = new ImageIcon( "gfr.gif" );
          this.setIconImage( gfr.getImage() );
          // get content pane set a layout
          java.awt.Container c = getContentPane();
          c.setLayout( new BorderLayout( 0, 0 ) );
          // create panel to hold web cam image
          campanel = new JPanel();
          campanel.setLayout( new BorderLayout( 0, 0 ) );
          campanel.setPreferredSize( new Dimension( 320, 240 ) );
          // locate web cam from JMF Registry
          ml = new MediaLocator( "vfw://0" );
          // set lightweight renderer for improved framerate
          Manager.setHint( Manager.LIGHTWEIGHT_RENDERER, new Boolean(true) );
          try
               // create realized video player
               player = Manager.createRealizedPlayer( ml );
               //start player
               player.start();
               Component comp;
               // display the visual component
               if ( ( comp = player.getVisualComponent() ) != null )
                    campanel.add( comp, BorderLayout.CENTER );
          catch (Exception e)
               System.err.println( "Exception in creating or displaying player" );
               System.err.println( e.getMessage() );
          // add campanle to the frame
          c.add( campanel, BorderLayout.CENTER );
          // size & colour of frame
          c.setBackground( backcolour );
          setBounds( 0, 0, 0, 0 );
          setResizable( false );
          setSize( 350, 250 );
          show();
          // active set to true - means software is listening for image requests
          active = true;
     // Thread listener for image requests
     public void execute()
          // while active is true          
          while ( active )
               try
                    // client connects
                    ClientApplet newclient = new ClientApplet( server.accept(), this );
                    // 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);
                    // set client thread with image
                    newclient.setImage( img );
                    // start the client thread
                    newclient.start();
               catch( IOException e )
                    e.printStackTrace();
                    System.exit( 1 );
// ClientApplet class to manage each Client Applet as a thread
class ClientApplet extends Thread
     // class variables
     private Socket connection;
     private PrintWriter out;
     private BufferedReader in;
     private WebCamServer control;
     protected boolean threadSuspended = true;
     public Image img;
     // constructor creates a socket on port 8080
     public ClientApplet( Socket s, WebCamServer t )
          connection = s;          
          control = t;
     // grabbed frame set as output image
     public void setImage( Image img )
          this.img = img;
public void run()
          // image is buffered to create a 2D graphics object               
          BufferedImage bi = new BufferedImage(240, 180, BufferedImage.TYPE_INT_RGB);
          Graphics2D g2 = bi.createGraphics();
          g2.drawImage(img, null, null);
          OutputStream out = null;
          // create an output stream to the socket
          try
               out = connection.getOutputStream();
          catch ( IOException io)
               System.out.println("Error getting socket output stream");
               System.err.println( io.getMessage() );
          // create jpeg encoder on output stream
          // set the image as a parameter
          JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
          JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bi);
          param.setQuality(0.25f,false);
          encoder.setJPEGEncodeParam(param);
          // encode the image through the output stream
          // close IO connections
          try
               encoder.encode(bi);
               out.close();
               connection.close();
          catch ( IOException ioe )
               System.out.println("JPGE IO exception");
               System.err.println( ioe.getMessage() );
          // end of thread image is served to webpage or applet
}

Hi,
I don't know how to solve this problem,
but I want to ask you how you managed to get
FrameGrabbingControl which is not null.
I use Logitech QickCam and everytime when I try to get a FrameGrabbingControl from the Player it returns me null?
Can you help me?
have you any ideas why I get null?
WebCamLocator - is OK. If I can use it to record a video clip. But I can't take a single frame..
Manager.setHint( Manager.LIGHTWEIGHT_RENDERER, new Boolean(true) );
Player WebCamPlayer = Manager.createRealizedPlayer(WebCamLocator);
WebCamPlayer.start();
FrameGrabbingControl fgc = (FrameGrabbingControl)WebCamPlayer.getControl("javax.media.control.GrabbingControl");
Buffer buf = fgc.grabFrame();

Similar Messages

  • May I receive resolution 640*480 in image LV from WEB-camera

    Hello all
    I have
    LV7.1.1
    I received
    the image from WEB-camera.
    WEB-camera
    has resolution 640*480 but I have resolution in the Image of LV -  320*240.
    May I
    receive resolution 640*480 in LV
    With respect.
    Aleksandr

    Hello,
    I assume you have to change the settings of the camera and not the code in LabVIEW...
    Just in case, see the attached code in LV 7.1.1 that allows to change the image resolution.
    Hope this helps
    When my feet touch the ground each morning the devil thinks "bloody hell... He's up again!"
    Attachments:
    AC_Util_ResampleImage.vi ‏126 KB

  • Video Streaming on Web Browser from Web Camera

    How to run Web Camera on to the Web Browser through JAVA and JMF?

    How to run Web Camera on to the Web Browser
    through JAVA and JMF? As someone who has written dozens of applets, and
    helped debug hundreds of them, I can tell you that
    applets are not for beginners.
    Whenever I must have an applet that is any more
    than completely trivial, I will code it as a combined
    application/applet, if only for making testing faster
    and easier.
    Further, if you have a working application, it can be
    'launched from a link', just like an applet, but using
    web start.
    I suggest you put aside the applet idea for the
    moment, and concentrate on doing this in an
    application.
    When that is working, you can decide whether
    to launch it using web start, or embed it as an
    applet in a web page.
    Here is an example of launching JMF (the
    player) using web start.
    http://www.javasaver.com/testjs/jmf/#test5
    As far as coding for a web cam, a quick Google leads to..
    "Here is the source code to JMF Webcam app + saves jpeg"
    http://forum.java.sun.com/thread.jspa?threadID=247253
    2 notes:
    1) I found that URL for the web cam code using
    Google. I have never dealt with web cams myself.
    2) Normally I ignore threads with no dukes. I am
    usually pretty busy, and dukes indicate how
    important a thread is - to whoever is asking.
    So, if you want to complete this task faster, you might
    - search for answers first.
    - add dukes to any question, to indicate interest.
    HTH

  • Olnly Red when i upload from web cam go plus

    I have a creative web cam go plus that I have purchased many moons ago and am running winXP.. I have all the latest drivers as well as the disks that came with the cam.. I have done a hard reboot of the cam that was suggested by a creative rep and now I can not get my pic. to upload to my puter from the cam itself, all I get is red pic
    There is also a issue of the cam can not load one of the disks do to a 6 bit problem...any help out there at all

    Hi, I have the same problem ! Always red image. Have you the solution ?

  • ClassNotFound error while running applet from Web application

    hi everyone,
    I have a web application deployed in Tomcat web server. I have HTML file at the level of WEB-INF. And all class files under WEB-INF/classes. But while ruuning the application it giving following error.
    load: class com.app.AppletTest not found.
    java.lang.ClassNotFoundException: com.app.AppletTest
         at sun.applet.AppletClassLoader.findClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.applet.AppletClassLoader.loadClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.applet.AppletClassLoader.loadCode(Unknown Source)
         at sun.applet.AppletPanel.createApplet(Unknown Source)
         at sun.plugin.AppletViewer.createApplet(Unknown Source)
         at sun.applet.AppletPanel.runLoader(Unknown Source)
         at sun.applet.AppletPanel.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)
    Caused by: java.io.IOException: open HTTP connection failed.
         at sun.applet.AppletClassLoader.getBytes(Unknown Source)
         at sun.applet.AppletClassLoader.access$100(Unknown Source)
         at sun.applet.AppletClassLoader$1.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         ... 10 more
    Here the HTML file applettest.html
    <html>
         <head>
              <title>Multiple Image Upload</title>
         </head>
         <body>
              <applet code="com.app.AppletTest" width="300" height="300">
              </applet>
         </body>
    </html>
    And Java applet file is
    package com.app;
    import java.applet.Applet;
    import java.awt.Color;
    import java.awt.Graphics;
    public class AppletTest extends Applet
         public void init()
              System.out.println("Init called");
              this.setBackground(new Color(180,200,250));
         public void start()
              System.out.println("Start called");
         public void paint(Graphics g)
              g.drawString("welcome Hello World",50,50);
              System.out.println("Paint called");
         public void stop()
              System.out.println("Stop called");
         public void destroy()
              System.out.println("Destroy called");
    Thanks.

    Hi,
    if u put ur com.app.AppletTest file @ WEB-INF Directry, then this problem will solve easily.
    you have to put applet package(com.app.AppletTest) @ WEB-INF Directry. Since
    Applet is using by html, u have to keep applet with html file.
    if applet class have interaction with other classes, u have to seperate all related class to applet to seperate package and put them @ WEB-INF folder.

  • Safari 6.0.5 Mac won't "SAVE IMAGE AS" jpegs from web pages

    Hi. Trying to figure out what has changed here.
    In the past, when I've located a specific graphic on a web page — say, a .png or .jpg file through a Google image search in Safari — I could right click and choose "SAVE IMAGE AS" and download the image to my desktop.
    No more.
    Now Safari insists on appending ".webarchive" to the end of the file (for example, "image.jpg.webarchive" or "image.png.webarchive"), but won't let me download it. I tried to "SAVE IMAGE AS" a file called 27.png from a web page, for example, and got this error message:
    If I try to remove the ".webarchive" extension, I get this error message:
    I used to be able to simply right click an image, select "SAVE IMAGE AS" and save .jpg and .png files to my desktop. It still works that way in Firefox.
    I am not looking for workarounds or other ways to do this, as I have spent many years doing it this way and it has become habit; I am trying to find out how I can get the old Safari behavior back. Any ideas on why this behavior changed in Safari and how I can revert?

    @andyBall_uk
    Inexplicably, it is now working as it should. I don't get it, but I am not going to question it. I tried to figure it out for an hour, then read your reply, did the duck search you linked to and had no trouble "SAVING PICTURE AS" in .jpg form. It now works on the original images I was trying to download as well. I did not close or open Safari, nor did I restart my computer.
    I'm just going to go ahead and say that you fixed whatever was wrong. Nice work!

  • Images not loaded from WEB-INF/lib/images.jar

    The images are found in root/images/*.gif, but not
    when jarred up and placed in the lib folder. I've looked everywhere
    for a solution but all I've seen is suggestions of other places to put
    the folder, or to add it to the classpath.
    The jar is being loaded but the images are not found. Or at least the images are not showing up - the table where the main image is linked expands to the size of the image when the path is correct.
    Does anyone know the solution to this problem? I don't want to just leave them in the folder at root level, because this does not work if I set a default url pattern for the control servlet.
    Thanks,
    Greg

    The images are found in root/images/*.gif, but not
    when jarred up and placed in the lib folder. I've
    looked everywhere
    for a solution but all I've seen is suggestions of
    other places to put
    the folder, or to add it to the classpath.
    The jar is being loaded but the images are not found.
    Or at least the images are not showing up - the table
    where the main image is linked expands to the size of
    the image when the path is correct.
    Does anyone know the solution to this problem? I don't
    want to just leave them in the folder at root level,
    because this does not work if I set a default url
    pattern for the control servlet.
    Thanks,
    GregIf your planning to make the images accessible by normal html tags - img etc, then they cant be in a jar, and they must be in a location from which the container serves content - i.e not under WEB-INF. Unless you want to write a special servlet which does nothing but read the images and feed them to the client - but I wouldnt recommend that.
    Sounds like your using Struts, and sounds like youre not using weblogic since you wouldnt be able to serve even jsp�s (using forward) from under WEB-INF if you were. Putting jsp�s under WEB-INF sounds like such a good idea when using Struts, but in practice...

  • Quicktime file becomes corrupted only after transfer from a camera

    I have encountered an unusual Quicktime-related problem with a customer that I cannot solve. This has been tested on two different cameras (a Kodak Zi6 and a Casio EX-Z80) to verify it is not camera related. The customer has also tested it on his desktop and laptop computers to verify it occurs on both. It must be confined to some specific piece of software he installs, because I've never run into this problem elsewhere. His two computers both run Vista.
    1. He shoots video.
    2. Opens Quicktime.
    3. Plays the video (AVI or MOV... doesn't matter) while the video RESIDES on his camera. It plays fine.
    4. Has tried taking the SD card out of the camera, putting it into his laptop, then playing the video while it resides on the card. It plays fine.
    5. BUT... the moment he transfers the video file to his desktop and plays it in Quicktime, it becomes corrupted. It does play, but the image develops all kinds of blockyness and distorted colors. It becomes useless.
    Any clues as to which software program he is installing that makes this problem occur? I have hundreds of other customers who use these same cameras and have no similar problem.
    Thanks.
    Richard

    The video file is able to be transfered to the hard drive of the computer and it does play with QT, but with blockyness and distorted colors, correct? That would suggest to me video card and\or driver. The reason being if the file was not supported by QT or WMP it would not even play. QT would produce error 2048 and WMP would inform it could not handle the file. But...
    I would go to the Window menu of QT player and click on Show Movie Inspector to get some info on the video file.
    salaminizer, makes a good point on the possibilty of NTFS\FAT32 file systems. Right clicking on My Computer>Manage>Disk Management will show info of HD's on the computer. Some bought computers will have a back-up Partition that uses Fat32. Which the video might be being saved to.
    I'm thinking video card and drivers, but on two separate computers? So find out the video codecs. It's tough unless you have the same camera or what software came with it? Let me know how you make out.

  • Is it possible to preview images full screen from web albums?

    Tried to browse my Picasa web album on the Z10. Photos shown of a thingernail size! (photos in album are 1280x1024)
    Is there a way to browse web albums on Z10 and see images on the full screen?

    Could you please explain? I am having the same problem and so far I was not able t ofind a way how to view full size (or full screen) images.

  • Remove Firefox applet from web pages.

    I returned to Firefox after six months of using Chrome. I now have an obnoxious Facebook java applet on every site I open. The only way I could remove it was by shutting down all java. I would rather not do this but I can't stand that damn icon on every page. Please help me remove it.
    Thanks.

    Sorry to bother you folks. I found the culprit. Akamaihd.net

  • No images will import from my camera card into Lightroom 3.  Shooting with a Nikon D700 and using a MacBook Pro.  Used to work perfectly

    Any thoughts?  I can use Camera Raw, but miss LR.

    The D700 requires at least Lightroom 4.6. I believe you are mistaken if you thought you could import them into Lightroom 3 because it never included support for that camera.

  • What is the steps to capture from web cam and send it over internet?

    hello
    i need to capture video and send it over internaet?
    what is the steps to do it
    does i need RTP? how it work?
    thanks for help

    hello
    i need to capture video and send it over internaet?
    what is the steps to do it
    does i need RTP? how it work?
    thanks for help

  • Web cam applet

    Hi everybody ,
    i have started to write in java , recently and now i want to make one applet.
    My applet will show and record video from web cam and also it will play the recorded video. Please give me some advices and tutorials ?

    I have been trying to do this as well. You have to use JMF.
    The problem I have is that I can no longer get the camera to work in an applet.
    I have posted in the JMF forum and have not recieved an answer.
    I created an application that worked a couple years ago, but after upgrading to the latest JMF and JDK and camera drivers, I can no longer get the camera to work in the browser.
    It works fine in the Appplet Viewer, but not a browser.
    I am using IE6 and JBuilder 2005 with a Logitech USB camera.
    It is not a jar signing issue - I get asked if I want to accept the certificate.
    I am not sure if it is an IE6 issue or something in the JMF, JDK, or camera driver updates.
    I also had web based cameras (Axis and Dlink) working, but have not had the luxury of time to test and see if these work with the latest JMF and JDK updates.

  • Set resolution the web camera from Remote Panel.

    Hello all
    I want to control the WEB-camera from Remote Panel
    I created the VI and I must to set the resolution of the WEB-camera (640*480 or 320*240).
    But I couldn’t to set resolution  from Remote Panel.
    What do I do?
    Best regards
    Iskander
    Attachments:
    USB_camera.png ‏15 KB

    Dear John H.
    Thanks for the answer
    I created the VI to observe the image from WEB-camera
    When I run the VI, I must to set the resolution the  WEB-camera.
    When I run the VI on the host computer , I can do this.
    But when I run the VI on Remote Panel, I can’t adjust  the resolution of the  WEB-camera from Remote Panel and the VI are stopped
    What can I do?
    With respect
    Iskander
    Attachments:
    image.png ‏237 KB

  • Caling Web Camera Image in Forms

    Hi Sir,
    i want to take a photo from web camera and want to display the photo on image item on my form.

    Again you need to use timer for calling each image taken from camera
    the camera is taking the photos in the my pictures quickcam images folder.
    for this you need to use the dir/b c:\mypictures\quickcam\images >zz.txt
    then use the text_io package to get the each and every file to read.
    then remove all the files and use read_image_file with the parameters as received now from the text_io package
    after opening the file zz.txt.
    timer should be of 1000 mili seconds.

Maybe you are looking for