package com.github.sarxos.webcam;

import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;


/**
 * Example demonstrating how to use webcam image transformer feature.
 *
 * @author Bartosz Firyn (SarXos)
 */
public class WebcamImageTransformerExample extends JFrame implements WebcamImageTransformer {

	private static final long serialVersionUID = 1L;

	private static final BufferedImage IMAGE_FRAME = getImage("frame.png");

	public WebcamImageTransformerExample() {

		Webcam webcam = Webcam.getDefault();
		webcam.setViewSize(WebcamResolution.VGA.getSize());
		webcam.setImageTransformer(this);
		webcam.open();

		JFrame window = new JFrame("Test Transformer");

		WebcamPanel panel = new WebcamPanel(webcam);
		panel.setFPSDisplayed(true);
		panel.setFillArea(true);

		window.add(panel);
		window.pack();
		window.setVisible(true);
		window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}

	@Override
	public BufferedImage transform(BufferedImage image) {

		int w = image.getWidth();
		int h = image.getHeight();

		BufferedImage modified = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);

		Graphics2D g2 = modified.createGraphics();
		g2.drawImage(image, null, 0, 0);
		g2.drawImage(IMAGE_FRAME, null, 0, 0);
		g2.dispose();

		modified.flush();

		return modified;
	}

	private static final BufferedImage getImage(String image) {
		try {
			return ImageIO.read(WebcamImageTransformerExample.class.getResourceAsStream("/" + image));
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	public static void main(String[] args) throws IOException {

		JFrame.setDefaultLookAndFeelDecorated(true);

		SwingUtilities.invokeLater(new Runnable() {

			@Override
			public void run() {
				try {
					UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
				} catch (Exception e) {
					e.printStackTrace();
				}
				new WebcamImageTransformerExample();
			}
		});
	}
}

@@ -46,26 +46,91 @@
 ava.awt.
-Graphics2D
+FlowLayout;%0D%0Aimport java.awt.Graphics2D;%0D%0Aimport java.awt.event.ActionEvent
 ;%0D%0Aimpor
@@ -158,24 +158,46 @@
 eredImage;%0D%0A
+import java.io.File;%0D%0A
 import java.
@@ -246,16 +246,81 @@
 ageIO;%0D%0A
+import javax.swing.AbstractAction;%0D%0Aimport javax.swing.JButton;%0D%0A
 import j
@@ -577,23 +577,8 @@
 ple 
-extends JFrame 
 impl
@@ -616,61 +616,8 @@
 %0D%0A%0D%0A
-%09private static final long serialVersionUID = 1L;%0D%0A%0D%0A
 %09pri
@@ -684,24 +684,73 @@
 e.png%22);%0D%0A%0D%0A
+%09private Webcam webcam = Webcam.getDefault();%0D%0A%0D%0A
 %09public Webc
@@ -786,48 +786,8 @@
 %0D%0A%0D%0A
-%09%09Webcam webcam = Webcam.getDefault();%0D%0A
 %09%09we
@@ -1063,24 +1063,454 @@
 %0D%0A%09%09
-window.add(panel
+JButton button = new JButton(new AbstractAction(%22capture%22) %7B%0D%0A%0D%0A%09%09%09private static final long serialVersionUID = 1L;%0D%0A%0D%0A%09%09%09@Override%0D%0A%09%09%09public void actionPerformed(ActionEvent event) %7B%0D%0A%09%09%09%09try %7B%0D%0A%09%09%09%09%09ImageIO.write(webcam.getImage(), %22PNG%22, new File(%22capture.png%22));%0D%0A%09%09%09%09%7D catch (IOException e) %7B%0D%0A%09%09%09%09%09e.printStackTrace();%0D%0A%09%09%09%09%7D%0D%0A%09%09%09%7D%0D%0A%09%09%7D);%0D%0A%0D%0A%09%09window.setLayout(new FlowLayout(FlowLayout.CENTER));%0D%0A%09%09window.add(panel);%0D%0A%09%09window.add(button
 );%0D%0A
@@ -1824,17 +1824,16 @@
 YPE_INT_
-A
 RGB);%0D%0A%0D

Change image type ARGB to RGB in example, refs #282