View Javadoc

1   package net.sf.mmapps.applications.developer.util;
2   
3   import java.awt.*;
4   import java.awt.image.*;
5   import java.io.*;
6   
7   import com.sun.image.codec.jpeg.*;
8   /***
9    * wrapper class to conver java.awt.Image into a jpeg encoded stream
10   **/
11  public class JpegCoder implements ImageObserver{
12  
13      /***
14       * encode a image to the OutputStream using jpeg
15       **/
16      public void encode(Image img, OutputStream out) throws IOException{
17  	int iw = img.getWidth(this);
18  	int ih = img.getHeight(this);
19  	BufferedImage bi = new BufferedImage(iw,ih,BufferedImage.TYPE_INT_RGB);
20  	Graphics2D big = bi.createGraphics();
21  	big.drawImage(img,0,0,iw,ih,this);
22  	
23  	JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
24  	JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bi);
25  	param.setQuality(1.0f, false);
26  	encoder.setJPEGEncodeParam(param);
27  	encoder.encode(bi);
28      }
29      public boolean imageUpdate(Image img, int x , int y , int w , int h, int z){
30  	return true;
31      }
32  }