programming-examples/java/Servlets_Session_Swing_Util/Creating JPEG Image.java

41 lines
1.1 KiB
Java
Raw Normal View History

2019-11-15 12:59:38 +01:00
Creating JPEG Image
import java.awt.*;
import java.io.*;
import java.awt.image.*;
import com.sun.image.codec.jpeg.*;
public class ScreenImage
{
public ScreenImage()
{
OutputStream out = null;
try
{
BufferedImage shot = (new Robot()).createScreenCapture(new Rectangle(0, 0, 800,600));
out = new BufferedOutputStream(new FileOutputStream("shot.jpg"));
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(shot);
}
catch (Exception exc)
{
exc.printStackTrace();
}
finally
{
try
{
if (out != null)
{
out.close();
}
System.exit(0);
}
catch (Throwable t) {}
}
}
public static void main(String[] args)
{
new ScreenImage();
}
}