WEB开发网
开发学院WEB开发Jsp 用java实现print screen,读取位图文件,将位图文... 阅读

用java实现print screen,读取位图文件,将位图文件转化位jpeg格式并保存成文件输出!

 2008-01-05 18:42:44 来源:WEB开发网   
核心提示:package screensaver;import java.awt.*;import java.awt.image.BufferedImage;import java.io.*;import java.util.*;import com.sun.image.codec.jpeg.*;import java.awt.

package screensaver;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.*;
import com.sun.image.codec.jpeg.*;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.awt.image.MemoryImageSource;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
public class ScreenPicSaver
{
  MediaTracker tracker = new MediaTracker(new Component()
  {});
  public ScreenPicSaver()
  {}
  public Image loadbitmap(String sdir, String sfile) //读取8位或24位的位图文件
  {
   Image image;
   System.out.PRintln("loading:" + sdir + sfile);
   try
   {
    FileInputStream fs = new FileInputStream(sdir + sfile);
    int bflen = 14; // 14 字节 BITMAPFILEHEADER
    byte bf[] = new byte[bflen];
    fs.read(bf, 0, bflen);
    int bilen = 40; // 40 字节 BITMAPINFOHEADER
    byte bi[] = new byte[bilen];
    fs.read(bi, 0, bilen);
    // 解释数据。
    int nsize = ( ( (int) bf[5] & 0xff) << 24)
      ( ( (int) bf[4] & 0xff) << 16)
      ( ( (int) bf[3] & 0xff) << 8)
      (int) bf[2] & 0xff;
    System.out.println("File type is :" + (char) bf[0] + (char) bf[1]);
    System.out.println("Size of file is :" + nsize);
    int nbisize = ( ( (int) bi[3] & 0xff) << 24)
      ( ( (int) bi[2] & 0xff) << 16)
      ( ( (int) bi[1] & 0xff) << 8)
      (int) bi[0] & 0xff;
    System.out.println("Size of bitmapinfoheader is :" + nbisize);
    int nwidth = ( ( (int) bi[7] & 0xff) << 24)
      ( ( (int) bi[6] & 0xff) << 16)
      ( ( (int) bi[5] & 0xff) << 8)
      (int) bi[4] & 0xff;
    System.out.println("Width is :" + nwidth);
    int nheight = ( ( (int) bi[11] & 0xff) << 24)

Tags:java 实现 print

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接