读书人

java另存图片底色变黑有关问题

发布时间: 2013-08-09 15:16:24 作者: rapoo

java另存图片底色变黑问题

BufferedImage bufferImage;

File outputFile = null;

try{

? ? ?Image image = ImageIO.red(new File("c:\\pic\\aa.jpeg"));

? ? ?int width = image.getWidth(null);

? ? ?int height = image.getHeight(null);

? ? ?bufferImage= new?BufferedImage?(width,height,BufferedImage.TYPE_INT_RGB);

? ? ? ?bufferImage.getGraphics().drawImage(image,0,0,width,height,image.getGraphics().getColor(),null);//设置底色

?

? ? ? ?outputFile?= new File("c:\\pic\\bb.jpeg");

? ? ? ?if(!outputFile.exists())

? ? ? ? ? ??outputFile.mkdirs();

? ? ? ?ImageIO.write(bufferImage,"jpeg",outputFile);

}catch(IOException e){

? ? ?e.printStackTrace();

}

读书人网 >编程

热点推荐