Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7941133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:34:37+00:00 2026-06-03T23:34:37+00:00

Language: Java It is used in addition: JMF Below is the code (without the

  • 0

Language: Java
It is used in addition: JMF

Below is the code (without the Swing-forms), which allows to capture the image with WEB-cameras:

MediaLocator getWebCam = new MediaLocator("vfw://0");
    private Player player;
    Timer timer = new Timer(40, this);

    public BufferedImage grabFrameImage() {

        Image image = null;
        FrameGrabbingControl frameGrabbingControl = null;

        if (player != null)
            frameGrabbingControl = (FrameGrabbingControl) player.getControl("javax.media.control.FrameGrabbingControl");
        Buffer buffer = frameGrabbingControl.grabFrame();
        if (buffer != null)
            image = new BufferToImage((VideoFormat) buffer.getFormat()).createImage(buffer);
        if (image != null)
            return (BufferedImage) image;

        return null;
    }

    public WorkWithWebCam() throws NoDataSourceException, IOException, NoPlayerException {

            initComponents();
            player = Manager.createPlayer(Manager.createDataSource(getWebCam));
            player.start();

    }
private void jButton1ActionPerformed(ActionEvent e) {
        timer.start();
    }

    public static void main(String args[]) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try{
                    new WorkWithWebCam().setVisible(true);
                }catch(Exception ex){}
            }
        });
    }

    public void actionPerformed(ActionEvent e) {
        panelMain.getGraphics().drawImage(this.grabFrameImage(), 0, 0, 400, 300, null);
    }

Can you please tell how to save an image with a web-camera?

Looking ahead, we extended the method actionPerformed:

public void actionPerformed(ActionEvent e) {
        panelMain.getGraphics().drawImage(this.grabFrameImage(), 0, 0, 400, 300, null);
        BufferedImage image = new BufferedImage(400, 300, BufferedImage.TYPE_INT_RGB);
        String fileOut = "temp.jpg";
        Graphics g = image.getGraphics();
        panelMain.paint(g);
        try {
            ImageIO.write(image, "jpg", new FileOutputStream(fileOut));
        } catch (IOException e1) {
            e1.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }

    }

The only thing, no picture is saved with a web-camera, and the white background with a vertical stripe on the right.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T23:34:39+00:00Added an answer on June 3, 2026 at 11:34 pm
    image = new BufferToImage((VideoFormat) buffer.getFormat()).createImage(buffer);
    ImageIO.write(image, "png", new File("screengrab.png"));
    

    See ImageIO.write(RenderedImage,String,File) for details.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

JIT compilers are used to convert java byte-code into native machine language. And as
What is the correct way of knowing operating system language (locale) from java code?
Lamdbaj allows the definition of closures in the Java language, various examples can be
Aside from the language used (Java, C#, etc.), are articles and books for Hibernate
For those that don't know, processing is a language/ Java library primarily used for
Since its possibly one of the most widely used methods of the Java language,
Based on my understanding of the Java language, static variables can be initialized in
I was searching a bit for another platform independent language like Java. Are there
As you maybe know, as Java language perspective all method in C# are final
I have a Scala/Java dual language project where I need to pass a Scala

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.