import java.awt.*;
import java.awt.image.BufferedImage;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.util.*;
import com.sun.image.codec.jpeg.*;
public class Viewer extends Frame {
private Image image;
public Viewer(String fileName) {
System.setProperty("http.proxySet", "true");
System.setProperty("http.proxyHost", "10.1.1.50");
System.setProperty("http.proxyPort", "8080");
System.setProperty("http.proxyType", "4");
String proxyUser = "",
proxyPassword = "";
try{
URL u1 = new URL("http://10.1.1.82/jpg/image.jpg");
try{
URLConnection con = u1.openConnection();
con.setRequestProperty("Proxy-Authorization",
"Basic " + new sun.misc.BASE64Encoder().encode(
(proxyUser + ":" + proxyPassword).getBytes()));
con.connect();
u1.openConnection();
Toolkit toolkit = Toolkit.getDefaultToolkit();
image = toolkit.getImage(u1);
MediaTracker mediaTracker = new MediaTracker(this);
mediaTracker.addImage(image, 0);
try
{
mediaTracker.waitForID(0);
}
catch (InterruptedException ie)
{
System.err.println(ie);
System.exit(1);
}
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0); }});
setSize(image.getWidth(null), image.getHeight(null));
setTitle(fileName);
show();
saveJPG(image,"k:\\cam\\webcam.jpg");
}
catch(IOException e){}
}
catch(MalformedURLException e){}
}
public void paint(Graphics graphics) {
graphics.drawImage(image, 0, 0, null);
}
public static void saveJPG(Image img, String s)
{
BufferedImage bi = new BufferedImage(640, 480, BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = bi.createGraphics();
g2.drawImage(img, null, null);
FileOutputStream out = null;
try
{
out = new FileOutputStream(s);
}
catch (java.io.FileNotFoundException io)
{
System.out.println("File Not Found");
}
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bi);
param.setQuality(0.9f,false);
encoder.setJPEGEncodeParam(param);
try
{
encoder.encode(bi);
out.close();
}
catch (java.io.IOException io)
{
System.out.println("IOException");
}
}
public static void main(String[] args) {
for(int i=0; i<100; i++)
new Viewer("Webcam");
}
}