import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import com.sun.image.codec.jpeg.ImageFormatException;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
public class PictrueProess
{
public void createImage(int month,int output)
{
BufferedImage buf = new BufferedImage(300,600,BufferedImage.TYPE_INT_BGR);
Graphics2D g2 = buf.createGraphics();
g2.setPaint(Color.white); //这句是改背景色吗? 可是最后画出来的图片还是黑背影! 画出来的线却变成了白色! 谢了!
g2.drawRect(0, 0, month, output);
FileOutputStream outfile = null;
try
{
outfile = new FileOutputStream("c:\\test.jpg");
}
catch (FileNotFoundException e1)
{
e1.printStackTrace();
}//输出图片
JPEGImageEncoder jpge = JPEGCodec.createJPEGEncoder(outfile);
try {
jpge.encode(buf); //这二句蓝的能用imageio包中的哪个类的哪个方法能产生同样的作用,再谢了!我找半天API了..
} catch (ImageFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args)
{
PictrueProess p = new PictrueProess();
p.createImage(20, 60);
}
}
一共二个问题!在线等高手帮助解决一下~~~~